我想实现以下布局。等宽度的所有按钮
如何使按钮0等于按钮的其余部分。请注意,我已使用layout_weight = "1"
,以便所有其他按钮在匹配父项时具有相同的长度。因为,我在不同的布局上创建了按钮0,所以我似乎无法使其与其他按钮的长度相同。
这里是我到目前为止的代码
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/seven"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
<Button
android:id="@+id/eight"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
<Button
android:id="@+id/nine"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/zero"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
创建两个“虚拟”按钮,它们在按钮“0”的两侧是不可见的。但让我建议你使用一个GridView,而不是一堆LinearLayouts。 –