【发布时间】:2016-01-09 04:35:10
【问题描述】:
我在 Android Studio 中工作,希望我的布局是一个 2 x 2 的按钮网格,中间有一个按钮。请参阅下面的代码。
<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"
android:id="@+id/incentivebutton">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Incentive"
android:id="@+id/incentiveButton"
android:onClick="IncentiveButton"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:nestedScrollingEnabled="true"
android:background = "@drawable/roundbutton"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:paddingTop="55dp"
android:paddingBottom="55dp"
android:layout_gravity="center_vertical" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dp"
android:weightSum="2"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<Button
android:id="@+id/buttonCollect"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:layout_weight="1"/>
<Button
android:id="@+id/buttonCollect1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1">
<Button
android:id="@+id/buttonCollect3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:layout_weight="1" />
<Button
android:id="@+id/buttonCollect2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
这就是现在的样子:
我喜欢这种布局,但我希望按钮的高度为 50%。有人有什么建议吗?
【问题讨论】:
标签: android xml android-layout android-studio android-linearlayout