我想實現以下佈局。等寬度的所有按鈕
如何使按鈕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。 –