考慮下面的代碼和輸出:Android:爲什麼同樣重量的按鈕具有不同的寬度?
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ABCDE" />
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="A" />
<Button
android:id="@+id/button3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ABC" />
</TableRow>
</TableLayout>
的按鈕給出相同layout_weight
,但具有不同的寬度。爲什麼他們不佔用相同的寬度?我能做些什麼來使它們具有相同的寬度(不給像素值)?
用按鈕上的0dip更改layout_witdh,然後參閱。它適用於我 – Daler
@Daler你可能想把它作爲答案。 ;) – Eric
@Daler這似乎工作,但是什麼原因? – siva636