在相对布局中包装线性布局
Wrap linearlayouts in relativelayout
我正在尝试将两个 LinearLayouts 放在一个 RelativeLayout(根元素)中。我只能看到一排。 ÄÄ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>
因为你把两个线性布局的高度设置为"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">
我正在尝试将两个 LinearLayouts 放在一个 RelativeLayout(根元素)中。我只能看到一排。 ÄÄ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>
因为你把两个线性布局的高度设置为"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">