Почему таблицы TableLayout и LinearLayout не совпадают? Или у меня есть ошибка в XML-макетах?Веса для TableLayout и LinearLayout не одинаковы
4 тест-кнопка
Я подготовил простой тест с 4 кнопки имеют вес 1,1,1,3. Результат не совпадает с TableLayout (один столбец) и LinearLayout (по вертикали).
На следующей ссылке вы можете увидеть скриншот как реализации TableLayout (слева), так и LinearLayout (справа).
По моему мнению, LinearLayout верна - сумма равна 6, поэтому четвертая кнопка с весом 3 должна занимать половину пространства.
TableLayout XML
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="A" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="B" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="C" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3" >
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="D" />
</TableRow>
</TableLayout>
LinearLayout XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="A" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="B" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="C" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:text="D" />
</LinearLayout>
Environment
ADT: 22.6.2
AVD: Intel Atom с 4.2.2 и 4.4.2 (оба одинакового результата)
Вы правы. Все веса суммируются, TableRow и Button. В любом случае весы кнопки были излишними, как я проверял. Спасибо. – bocekm