如何在同一行上使用四個按鈕進行XML佈局。我需要第一個和最後一個按鈕具有特定寬度(40px),中間兩個按鈕的內容寬度(wrap_content)是?Android佈局問題
樣我想怎麼定位按鈕...
| -b1- | .... | --b2-- || --- B3 --- | .... | - B4- |
在此先感謝!
如何在同一行上使用四個按鈕進行XML佈局。我需要第一個和最後一個按鈕具有特定寬度(40px),中間兩個按鈕的內容寬度(wrap_content)是?Android佈局問題
樣我想怎麼定位按鈕...
| -b1- | .... | --b2-- || --- B3 --- | .... | - B4- |
在此先感謝!
只需將四個按鈕放在水平LinearLayout中即可。使用layout_width爲40px的b1和b3定義b1,使用wrap_content的layout_width,然後使用layout_width爲40px的b4。如果你想讓它居中,只需將LinearLayout的layout_width設置爲fill_parent並給它一個center_horizontal的引力。就像:
編輯:哦,如果你想兩側的兩個40px按鈕,並且兩個wrap_content按鈕居中,你可以去兩種方式。最簡單的方法是將一些空白視圖添加到您的LinearLayout(下面我將證明),而一個較爲漫長的方法是使用的RelativeLayout,把兩個中心按鈕,RelativeLayout的內內的LinearLayout:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_width="wrap_content"
>
<Button
android:layout_width="40px"
android:layout_height="wrap_content"
android:text="Button 1"
/>
<View
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3"
/>
<View
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<Button
android:layout_width="40px"
android:layout_height="wrap_content"
android:text="Button 4"
/>
</LinearLayout>
謝謝!那正是我想要的! – hades985 2010-12-17 22:37:41
哇,很久以前。假設你已經閱讀過文檔,但我很確定那裏有類似的東西。 – jocap 2010-12-17 21:43:45
我曾嘗試閱讀SDK文檔,但找不到我需要的內容... – hades985 2010-12-17 22:03:09