如何在Android中的relativelayout内放置LinearLayouts?

时间:2018-12-18 17:08:01

标签: android android-layout xamarin.android android-linearlayout android-relativelayout

如何将LinearLayout放在LinearLayout内的其他RelativeLayout之上或之下

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/RelativeLayout1>
    <LinearLayout
         android:layout_width="350dp"
         android:layout_height="match_parent"
         android:layout_centerHorizontal="true"
         android:layout_alignParentBottom="true"
         android:layout_above="@id/contentLayout"
         android:orientation=vertical
         android:translationZ="2dp"
         android:id="@+id/contentLayout">
    </LinearLayout>
    <LinearLayout
         android:layout_height="wrap_content"
         android:layout_width="match_parent"
         android:orientation="horizontal"
         android:layout_alignParentBottom="true"
         android:translationZ="2dp"
         android:id="@+id/settingslayout">
    <ImageButton
        android:src="@android:drawable/ic_menu_gallery"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/refreshImageButton"/>
    <ImageButton
        android:src="@android:drawable/ic_menu_gallery"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="20"
        android:id="@+id/selectedImageButton"/>
    <ImageButton
        android:src="@android:drawable/ic_menu_gallery"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/settingsImageButton"/>
     </LinearLayout>
 </RelativeLayout>

contentLayoutsettingslayout重叠如何将其放在settingslayout上方?

enter image description here

2 个答案:

答案 0 :(得分:1)

`<LinearLayout
     android:layout_width="350dp"
     android:layout_height="match_parent"
     android:layout_centerHorizontal="true"
     android:layout_above="@id/settingslayout"/*you should enter settinglayout*/
     android:orientation=vertical
     android:translationZ="2dp"
     android:id="@+id/contentLayout">
</LinearLayout>`

答案 1 :(得分:0)

将RelativeLayout更改为LinearLayout并分配权重而不是设置高度。请遵循以下代码;

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/RelativeLayout1>
<LinearLayout
     android:layout_width="350dp"
     android:layout_height="0dp"
     android:layout_weight=" 3 "
     android:layout_centerHorizontal="true"
     android:layout_above="@id/contentLayout"
     android:orientation=vertical
     android:translationZ="2dp"
     android:id="@+id/contentLayout">
</LinearLayout>
<LinearLayout
     android:layout_height="0dp"
     android:layout_weight="1"
     android:layout_width="match_parent"
     android:orientation="horizontal"
     android:layout_alignParentBottom="true"
     android:translationZ="2dp"
     android:id="@+id/settingslayout">
<ImageButton
    android:src="@android:drawable/ic_menu_gallery"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:id="@+id/refreshImageButton"/>
<ImageButton
    android:src="@android:drawable/ic_menu_gallery"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="20"
    android:id="@+id/selectedImageButton"/>
<ImageButton
    android:src="@android:drawable/ic_menu_gallery"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:id="@+id/settingsImageButton"/>
 </LinearLayout>
 </RelativeLayout>