我正在使用android应用程序。
我有问题,我的LinearLayout
小部件在屏幕上不可见。
这是我的布局
<LinearLayout
android:id="@+id/linear_layout_row_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:id="@+id/linear_layout_row1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="60dp"
android:layout_marginEnd="60dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
// Other widgets
</LinearLayout>
<LinearLayout
android:id="@+id/linear_layout_row2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="60dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="60dp"
android:layout_marginBottom="40dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="1">
// Other widgets
</LinearLayout>
<LinearLayout
android:id="@+id/linear_layout_row3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="60dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="60dp"
android:layout_marginBottom="40dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
// Other widgets
</LinearLayout>
</LinearLayout>
在这种情况下,linear_layout_row3
在屏幕上不可见。
如果我将其向上移动,将显示出来,但是下面移动的布局将不可见。
我不明白这个问题,您能帮忙找到它吗?
问题是嵌套LinearLayouts
的权重总和等于3(1 + 1 + 1)。
但是,标识为LinearLayout
的根linear_layout_row_container
具有android:weightSum="2"
。
因此,最后一个孩子将不可见。
像这样将其更改为3
:
<LinearLayout
android:id="@+id/linear_layout_row_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:orientation="vertical"
android:weightSum="2">
// Nested layouts
</LinearLayout>
这应该可以正常工作。
更改android:id="@+id/linear_layout_row_container
android:weightSum="2"
到
android:weightSum="3"
尝试一下:
<LinearLayout
android:id="@+id/linear_layout_row_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:orientation="vertical"
android:weightSum="3">
<LinearLayout
android:id="@+id/linear_layout_row1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="60dp"
android:layout_marginEnd="60dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
// Other widgets
</LinearLayout>
<LinearLayout
android:id="@+id/linear_layout_row2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="60dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="60dp"
android:layout_marginBottom="40dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="1">
// Other widgets
</LinearLayout>
<LinearLayout
android:id="@+id/linear_layout_row3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="60dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="60dp"
android:layout_marginBottom="40dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
// Other widgets
</LinearLayout>
</LinearLayout>