Android 如何使布局具有相同的高度?
下面是我的布局xml代码:Android 如何使布局具有相同的高度?,android,layout,Android,Layout,下面是我的布局xml代码: <LinearLayout android:id="@+id/c" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <RelativeLayout
<LinearLayout
android:id="@+id/c"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/a"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
</RelativeLayout>
<RelativeLayout
android:id="@+id/b"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
</RelativeLayout>
</LinearLayout>
我在线性布局c中有两个相对位置a和b。a和b的高度可能不同。
我想让这两个相对物的高度与最高者相同。
我如何实现它 试试看
<LinearLayout
android:id="@+id/c"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="2" >
<RelativeLayout
android:id="@+id/a"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
</RelativeLayout>
<RelativeLayout
android:id="@+id/b"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
</RelativeLayout>
</LinearLayout>
希望它能帮助您将属性布局_weightsum=2放入布局c中 为布局a、b添加布局权重为1,并删除布局a、b的布局高度属性
LinearLayout
高度更改为match\u parent
。给出wrap\u内容
将固定线性布局
高度,以调整其子视图的大小RelativeLayout
高度更改为0dip
试试这个,它会自动为子布局分配相等的空间
<LinearLayout
android:id="@+id/c"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/a"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
</RelativeLayout>
<RelativeLayout
android:id="@+id/b"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
</RelativeLayout>
</LinearLayout>
使用表格布局,它会自动调整表格布局
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:shrinkColumns="1"
android:stretchColumns="1" >
<TableRow android:id="@+id/tableRow1" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Main Status "
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/retentionMainStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CLICK ME" />
</TableRow>
</TableLayout>
但我希望线性布局高度为2*max(a,b)。