在relativelayout中包装linearlayouts

时间:2016-11-29 11:42:37

标签: android-layout android-linearlayout android-xml android-relativelayout

我试图将两个LinearLayouts放在RelativeLayout(rootelement)中。我只能看到一排。不应该ÄÄandroid:layout_below **强制第二个Linearlayout位于第一个LinearLayout下面吗?

有什么问题?是因为LinearLayout本身就是一个ViewGroup?

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">

<LinearLayout
    android:id="@+id/addon1_row"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/weapon1_id"
        android:layout_width="100dp"
        android:layout_height="26dp"
        android:src="@mipmap/weapon1"
        android:adjustViewBounds="true"
        />

    <ImageView
        android:layout_width="100dp"
        android:layout_height="26dp"
        android:src="@mipmap/buy_button"
        android:adjustViewBounds="true"
        />
</LinearLayout>

<LinearLayout
    android:id="@+id/addon2_row"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:layout_below="@+id/addon1_row">

    <ImageView
        android:id="@+id/weapon2_id"
        android:layout_width="100dp"
        android:layout_height="26dp"
        android:src="@mipmap/weapon2"
        android:adjustViewBounds="true"
        />

    <ImageView
        android:layout_width="100dp"
        android:layout_height="26dp"
        android:src="@mipmap/buy_button"
        android:adjustViewBounds="true"

        />
</LinearLayout>


</RelativeLayout>

1 个答案:

答案 0 :(得分:1)

这是因为您已将两个线性布局的高度设置为"match_parent",只需将其设置为"wrap_content"

<LinearLayout
    android:id="@+id/addon1_row"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"   <== Here
    android:orientation="horizontal">


<LinearLayout
    android:id="@+id/addon2_row"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"   <== Here
    android:layout_below="@+id/addon1_row"
    android:orientation="horizontal">
相关问题