LinearLayout
我們可以通過使用Layout_Weight使它們佔據所有寬度並且每個寬度取決於它們的Layout_Weight值(或比率)來水平填充元素。我的問題是如何在RelativeLayout
的情況下做同樣的事情。沒有像Layout_Weight這樣的屬性。 我在我的項目中使用了RelativeLayout
,它包含4個按鈕,它們需要位於屏幕的底部,並且必須填滿整個寬度。如果我使用硬編碼Layout_Width="20dp"
或類似的東西。當我將縱向從縱向更改爲橫向時,它會產生問題,反之亦然。什麼與layout_weight相似
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/feed_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="@string/feed"
android:textColor="#FF000000" />
<Button
android:id="@+id/iwant_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/feed_button"
android:text="@string/iwant"
android:textColor="#FF000000" />
<Button
android:id="@+id/share_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/iwant_button"
android:text="@string/share"
android:textColor="#FF000000" />
<Button
android:id="@+id/profile_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/share_button"
android:text="@string/profile"
android:textColor="#FF000000" />
</RelativeLayout>
如果我使用填補母公司的每個按鈕只有最後一個按鈕將是可見....其餘全部將得到重疊 – Housefly 2012-04-04 10:08:51
OK,然後讓他們WRAP_CONTENT代替FILL_PARENT – vipin 2012-04-04 10:16:26
看到沒有什麼相對佈局爲重你可以使他們wrap_content或您在運行時創建它們計算每個按鈕的寬度作爲父寬度/ 4然後分配給按鈕仍然存在,你必須搞砸按鈕的位置 – vipin 2012-04-04 10:21:57