内部具有嵌套线性布局的相对布局.如何将线性布局定位在屏幕底部



>我有一个相对布局,里面有一个照片库和一个媒体播放器。 我的问题是我希望媒体播放器控件(暂停/播放/前进/快退)4 个按钮位于屏幕底部,同时保持其中心水平对齐。 我所做的是

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:id="@+id/main_audio_view"
android:layout_height="match_parent"
android:background="@drawable/backgroundimg"
tools:context="com.my.project.LaunchGalleryview">
   <LinearLayout android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:orientation="horizontal" 
        android:layout_centerInParent="true"
        android:gravity="bottom"
        >
   </LinearLayout>
</RelativeLayout>
线性布局

内的切口位于中心,但整个线性布局位于屏幕的中心。 我希望它位于屏幕底部。 我已经尝试过 andoird:gravity="bottom" 它仍然位于屏幕的中心,我怎样才能强制它位于底部?

而不是

android:layout_centerInParent="true"

android:layout_alignParentBottom="true" <!-- Bottom of the RelativeLayout -->
android:gravity="center" <!-- centers all child views within the LinearLayout -->

只需将android:layout_alignParentBottom="true"添加到 LinearLayout 中即可

在线性布局中尝试此操作

android:layout_alignParentBottom="true"

最新更新