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

时间:2016-02-28 15:15:11

标签: android android-layout

我有一个相对布局,里面有一个照片库和一个媒体播放器。我的问题是我希望媒体播放器控件(暂停/播放/前进/后退)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”它仍然位于屏幕的中心,我怎么能强迫它在底部?

3 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

在线性布局

中尝试此操作
android:layout_alignParentBottom="true"

答案 2 :(得分:0)

而不是

android:layout_centerInParent="true"

使用

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