android - 如何将 ViewGroup 对齐到屏幕底部

标签 android alignment android-relativelayout viewgroup layoutparams

因此,我有一个作为对话框启动的 Activity (Theme.Dialog)。我用它来播放视频,调暗背景,看起来很酷......但它总是在屏幕上居中并且不知道如何以编程方式将它移动到底部。

<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>

然后我以编程方式添加视频播放器(从第 3 方查看)。

我已经试过了:

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

还有这个:

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

但是视频还在中间。

有什么想法吗?

谢谢!

最佳答案

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

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

关于android - 如何将 ViewGroup 对齐到屏幕底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25941326/

相关文章:

html - CSS - 防止文本换行破坏 flex 对齐

css - 对齐对象

python - 如何将 QComboBox 中的文本设置为居中对齐而不使其在 PyQt 中可编辑

android - RelativeLayout 比 LinearLayout 贵吗?

Android 中的 Java Xml 解析器

java - 将方法绑定(bind)到android中的按钮

android - 引用错误 : Camera Is Not Defined

Android Eclipse - 表格行按钮 - 格式问题

android - ImageView 填充 parent 的宽度或高度,但保持纵横比

java - ListFragment,不显示数据