【发布时间】:2017-08-10 00:46:38
【问题描述】:
我在RelativeLayout 中有一个RelativeLayout 和5 个LinearLayouts。一个LinearLayout代表一行按钮,每个LinearLayout有4个按钮,每个按钮都有定义的宽度和高度。
我的问题是,当我将RelativeLayout 的高度设置为wrap_content 时,它不会包裹LinearLayout 的行,而是像fill_parent。有趣的是,它可以将RelativeLayout 的宽度设置为wrap_content但不是高度。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/fifthRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/forthRow"
android:layout_centerHorizontal="true">
<Button
android:id="@+id/bChangeBase"
android:layout_width="85dp"
android:layout_height="85dp"
android:background="@drawable/bnb"
android:onClick="onClickBaseChange" />
<!--- three more buttons --->
</LinearLayout>
<LinearLayout
android:id="@+id/firstRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
<Button
android:id="@+id/bP"
android:layout_width="85dp"
android:layout_height="85dp"
android:background="@drawable/bp" />
<!--- three more buttons --->
</LinearLayout>
<LinearLayout
android:id="@+id/thirdRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/secondRow"
android:layout_centerHorizontal="true">
<Button
android:id="@+id/b4"
android:layout_width="85dp"
android:layout_height="85dp"
android:background="@drawable/b4"
android:onClick="onClickB4" />
<!--- three more buttons --->
</LinearLayout>
<LinearLayout
android:id="@+id/forthRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/thirdRow"
android:layout_centerHorizontal="true">
<Button
android:id="@+id/b7"
android:layout_width="85dp"
android:layout_height="85dp"
android:background="@drawable/b7"
android:onClick="onClickB7" />
<!--- three more buttons --->
</LinearLayout>
<LinearLayout
android:id="@+id/secondRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/firstRow"
android:layout_centerHorizontal="true">
<Button
android:id="@+id/b1"
android:layout_width="85dp"
android:layout_height="85dp"
android:background="@drawable/b1"
android:onClick="onClickB1" />
<!--- three more buttons --->
</LinearLayout>
</RelativeLayout>
【问题讨论】:
-
你考虑过使用 GridLayout 还是表格?
标签: android xml android-layout layout