我一直在寻找最好的方式做这样一个布局:做一个布局,四个按钮可调整大小
底部的四个按钮应该占据尽可能大的空间,但每次都要与其他人具有相同的尺寸。 我试着用TableLayout和一些LinearLayout拼接在一起,但我无法得到我想要的结果。
我一直在寻找最好的方式做这样一个布局:做一个布局,四个按钮可调整大小
底部的四个按钮应该占据尽可能大的空间,但每次都要与其他人具有相同的尺寸。 我试着用TableLayout和一些LinearLayout拼接在一起,但我无法得到我想要的结果。
代码:
<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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="@+id/button4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
</LinearLayout>
您节省了我的一天:) – hyperloris 2013-02-21 13:09:03
@HyperLoris代码有效,但您应该避免嵌套权重,因为您可以通过更好的性能实现该布局。 – Luksprog 2013-02-21 13:14:06
有什么问题你有没有在你的代码面对? – 2013-02-21 12:49:02
你能提供我们你的代码吗? – itsrajesh4uguys 2013-02-21 12:53:17