У меня есть основной макет, в который я включаю два внутренних макета. Я указываю ширину включенных макетов в match_parent, но они не занимают всю ширину родителя.Android: включен макет, не заполняющий родительскую ширину
У меня может быть больше компонентов в каждом внутреннем LinearLayout, например, трех левых и трех правых кнопках. Ниже приведен упрощенный пример моего кода
пример ниже: main_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="5dp"
android:baselineAligned="false"
android:orientation="vertical" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.95" >
<TableRow
android:id="@+id/tableRow1"
android:layout_weight="0.8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp" >
<include layout="@layout/child_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_weight="0.2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp" >
<include layout="@layout/child_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="0.05"
android:gravity="center"
android:orientation="vertical">
<Button
android:layout_width="80dp"
android:layout_height="40dp"
android:textSize="14sp"
android:textStyle="bold"
android:text="Bottom" />
</LinearLayout>
</LinearLayout>
child_layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/leftLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="vertical" >
<Button
android:layout_width="80dp"
android:layout_height="40dp"
android:textSize="14sp"
android:textStyle="bold"
android:text="Left" />
</LinearLayout>
<LinearLayout
android:id="@+id/rightLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="vertical" >
<Button
android:layout_width="80dp"
android:layout_height="40dp"
android:textSize="14sp"
android:textStyle="bold"
android:text="Right" />
</LinearLayout>
</RelativeLayout>
Обратите внимание, что левая и правая кнопки перекрываются на изображении. . Как развернуть включенный макет, чтобы заполнить всю ширину родителя, чтобы левая и правая кнопки отображались слева и справа. Спасибо.
У меня может быть больше компонентов в каждом LinearLayout, например, три левых кнопки и три правой кнопки. Я предоставил упрощенный пример моего кода. Должен ли я назначать слева и справа все внутренние компоненты? – sony
Да, где бы вы ни были. Похоже, что больше работы и труднее понять, но IMHO, «RelativeLayout» - это простое управление, когда вы это понимаете. И это намного более гибко – codeMagic
Я добавил примечание к моему ответу на мои мысли – codeMagic