简体   繁体   中英

How to align ViewGroup to the bottom of the screen

So, I have an activity that is launched as a dialog (Theme.Dialog). I use it to play a video, dimming the background, and looks pretty cool... but it's always centered on the screen and don't know how to move it to the bottom programmatically.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/lr_layout"
            android:background="#FF000000"
            android:padding="0dp" >


<RelativeLayout
    android:id="@+id/lr_progressContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FF000000">

    <ProgressBar android:id="@+id/lr_progress"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerInParent="true"
      android:background="@android:color/black"
      style="@android:style/Widget.ProgressBar.Large" />

    <View android:id="@+id/disableShape"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="0dp"
    android:visibility="gone"
    android:background="#CC000000" 
    />
</RelativeLayout>

</RelativeLayout>

And then I add the video player programmatically (View from 3rd party).

I've tried this:

layout = (ViewGroup) findViewById(R.id.lr_layout);
layout.setY(0);

and this:

RelativeLayout.LayoutParams adViewLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
adViewLayoutParams.addRule(RelativeLayout.ALIGN_BOTTOM);
layout.addView(adView, adViewLayoutParams);

But the video is still in the center.

Any idea?

Thanks!

尝试将其放在您的onCreate方法中。

WindowManager.LayoutParams lp = getWindow().getAttributes(); lp.gravity = Gravity.BOTTOM; getWindow().set attributes(lp);

如果想将relativeLayout子项对齐到底部,可以将AlignParentBottom = true设置为如果要将对话框对齐到屏幕的底部,可以使用popupWindow!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM