我想知道,如果使用RelativeLayout,可以將2個或3個按鈕並排放置,並且它們的寬度均勻地設置在視圖中。例如如果屏幕爲300像素,按鈕將自動採用100像素寬度(假設沒有填充等)。在視圖中的等距按鈕寬度
我真的不能提供代碼...因爲我不知道該怎麼做= 0)
我想知道,如果使用RelativeLayout,可以將2個或3個按鈕並排放置,並且它們的寬度均勻地設置在視圖中。例如如果屏幕爲300像素,按鈕將自動採用100像素寬度(假設沒有填充等)。在視圖中的等距按鈕寬度
我真的不能提供代碼...因爲我不知道該怎麼做= 0)
我會把一個線性佈局的相對佈局內(假設您需要的RelativeLayout的其他東西)的方向水平,並給每個按鈕相同的重量。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right|center_vertical">
<!-- Some stuff above -->
<LinearLayout android:id="@+id/LinearLayout01" android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_alignParentLeft="true">
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/btn"
android:text="left" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/btn1"
android:layout_weight="1"
android:text="center"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/btn2"
android:layout_weight="1"
android:text="right"/>
</LinearLayout>
<!-- Or below -->
</RelativeLayout>
+1您可能想要添加一個示例以使其更好 – MByD 2011-05-06 22:52:59
有點惱火,我被稱爲新用戶,所以可以8個小時不回答我自己的問題,但我已經破解了它。類似於你所說的,但不完全。我會盡快發佈答案棧也允許我= 0( – 2011-05-06 23:13:37
有了這個解決方案,你還想設置按鈕寬度爲0dip。請參閱http://stackoverflow.com/questions/5459168 – 2011-05-06 23:47:27
看起來像你有一個Doppelgaenger。 http://stackoverflow.com/questions/5917489 – 2011-05-06 23:45:41
是的,我無法訪問我的帳戶或記得之前使用過什麼登錄方法...然後我記得。我已經在Stack上做了一個快速搜索,但是我必須使用錯誤的關鍵字= 0 \ – 2011-05-07 10:07:20