其他 LinearLayout 中缺少 Linearlayout
Linearlayout missing in inside other LinearLayout
我有两个 LinearLayout
如下结构。
<LinearLayout
android:orientation="vertical">
<LinearLayout
android:id="@+id/kanji"
android:layout_width="match_parent"
android:layout_height="120dp"/>
<LinearLayout
android:id="@+id/goi"
android:layout_width="match_parent"
android:layout_height="120dp">
</LinearLayout>
问题是第二个 LinearLayout
(id=goi
) 没有按预期显示。我尝试将顶部布局更改为 RelativeLayout
但它也不起作用。
为什么会这样?
我的实际代码:
<?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="120dp"
android:background="@drawable/rounded_corner_2"
android:layout_margin="10dp"
android:orientation="vertical">
<LinearLayout
android:id="@+id/kanji"
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="horizontal"
android:background="@drawable/rounded_corner_2"
android:layout_margin="0dp">
<TextView
android:layout_width="80dp"
android:layout_height="match_parent"
android:text="漢"
android:textColor="@color/green"
android:gravity="center"
android:textSize="70sp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/rounded_corner_2"
android:layout_margin="10dp"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="漢字"
android:textColor="@color/green"
android:textSize="20sp"
android:gravity="left"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="15dp"
android:text="漢字"
android:textColor="@android:color/darker_gray"
android:textSize="10sp"
android:gravity="left"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ProgressBar
android:layout_width="160dp"
android:layout_height="match_parent"
style="?android:attr/progressBarStyleHorizontal"
android:outlineSpotShadowColor="@color/green"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="end"
android:text="100/140"
android:textColor="@android:color/darker_gray"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/goi"
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="horizontal"
android:background="@drawable/rounded_corner_2"
android:layout_margin="0dp">
<TextView
android:layout_width="80dp"
android:layout_height="match_parent"
android:text="漢"
android:textColor="@color/green"
android:gravity="center"
android:textSize="70sp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/rounded_corner_2"
android:layout_margin="10dp"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="漢字"
android:textColor="@color/green"
android:textSize="20sp"
android:gravity="left"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="15dp"
android:text="漢字"
android:textColor="@android:color/darker_gray"
android:textSize="10sp"
android:gravity="left"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ProgressBar
android:layout_width="160dp"
android:layout_height="match_parent"
style="?android:attr/progressBarStyleHorizontal"
android:outlineSpotShadowColor="@color/green"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="end"
android:text="100/140"
android:textColor="@android:color/darker_gray"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Linearlayout missing in inside other LinearLayout
你的根 LinearLayout
高度是 120dp
你有 2 child LinearLayout
具有与 120dp
相同的高度,因此第二个 LinearLayout
到可见
没有 space
解决方案
将您的根 LinearLayout
更改为 android:layout_height="wrap_content"
它会起作用
试试这个
<LinearLayout
android:id="@+id/kanji"
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="horizontal"
android:background="@drawable/rounded_corner_2"
android:layout_margin="0dp">
<TextView
android:layout_width="80dp"
android:layout_height="match_parent"
android:text="漢"
android:textColor="@color/green"
android:gravity="center"
android:textSize="70sp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/rounded_corner_2"
android:layout_margin="10dp"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="漢字"
android:textColor="@color/green"
android:textSize="20sp"
android:gravity="left"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="15dp"
android:text="漢字"
android:textColor="@android:color/darker_gray"
android:textSize="10sp"
android:gravity="left"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ProgressBar
android:layout_width="160dp"
android:layout_height="match_parent"
style="?android:attr/progressBarStyleHorizontal"
android:outlineSpotShadowColor="@color/green"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="end"
android:text="100/140"
android:textColor="@android:color/darker_gray"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/goi"
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="horizontal"
android:background="@drawable/rounded_corner_2"
android:layout_margin="0dp">
<TextView
android:layout_width="80dp"
android:layout_height="match_parent"
android:text="漢"
android:textColor="@color/green"
android:gravity="center"
android:textSize="70sp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/rounded_corner_2"
android:layout_margin="10dp"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="漢字"
android:textColor="@color/green"
android:textSize="20sp"
android:gravity="left"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="15dp"
android:text="漢字"
android:textColor="@android:color/darker_gray"
android:textSize="10sp"
android:gravity="left"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ProgressBar
android:layout_width="160dp"
android:layout_height="match_parent"
style="?android:attr/progressBarStyleHorizontal"
android:outlineSpotShadowColor="@color/green"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="end"
android:text="100/140"
android:textColor="@android:color/darker_gray"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
父 LinearLayout 的高度为 120px,其第一个子项也是如此。所以第一个子LinearLayout填满了父布局的所有高度。
您可以增加父 LinearLayout 的高度或使其 "wrap_content" 以便它根据其内容动态调整高度。
这是因为您的顶部布局具有固定高度
<?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="120dp"
android:background="@drawable/rounded_corner_2"
android:layout_margin="10dp"
android:orientation="vertical">
更新为
<?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="wrap_content"
android:background="@drawable/rounded_corner_2"
android:layout_margin="10dp"
android:orientation="vertical">
您的父LinearLayuot 和子LinearLayouts 的高度为120dp。您需要更改子布局的高度以适应父布局
您可以使用指令 <include></include>
,但我建议在约束布局上进行实施
我有两个 LinearLayout
如下结构。
<LinearLayout
android:orientation="vertical">
<LinearLayout
android:id="@+id/kanji"
android:layout_width="match_parent"
android:layout_height="120dp"/>
<LinearLayout
android:id="@+id/goi"
android:layout_width="match_parent"
android:layout_height="120dp">
</LinearLayout>
问题是第二个 LinearLayout
(id=goi
) 没有按预期显示。我尝试将顶部布局更改为 RelativeLayout
但它也不起作用。
为什么会这样?
我的实际代码:
<?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="120dp"
android:background="@drawable/rounded_corner_2"
android:layout_margin="10dp"
android:orientation="vertical">
<LinearLayout
android:id="@+id/kanji"
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="horizontal"
android:background="@drawable/rounded_corner_2"
android:layout_margin="0dp">
<TextView
android:layout_width="80dp"
android:layout_height="match_parent"
android:text="漢"
android:textColor="@color/green"
android:gravity="center"
android:textSize="70sp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/rounded_corner_2"
android:layout_margin="10dp"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="漢字"
android:textColor="@color/green"
android:textSize="20sp"
android:gravity="left"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="15dp"
android:text="漢字"
android:textColor="@android:color/darker_gray"
android:textSize="10sp"
android:gravity="left"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ProgressBar
android:layout_width="160dp"
android:layout_height="match_parent"
style="?android:attr/progressBarStyleHorizontal"
android:outlineSpotShadowColor="@color/green"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="end"
android:text="100/140"
android:textColor="@android:color/darker_gray"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/goi"
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="horizontal"
android:background="@drawable/rounded_corner_2"
android:layout_margin="0dp">
<TextView
android:layout_width="80dp"
android:layout_height="match_parent"
android:text="漢"
android:textColor="@color/green"
android:gravity="center"
android:textSize="70sp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/rounded_corner_2"
android:layout_margin="10dp"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="漢字"
android:textColor="@color/green"
android:textSize="20sp"
android:gravity="left"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="15dp"
android:text="漢字"
android:textColor="@android:color/darker_gray"
android:textSize="10sp"
android:gravity="left"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ProgressBar
android:layout_width="160dp"
android:layout_height="match_parent"
style="?android:attr/progressBarStyleHorizontal"
android:outlineSpotShadowColor="@color/green"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="end"
android:text="100/140"
android:textColor="@android:color/darker_gray"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Linearlayout missing in inside other LinearLayout
你的根 LinearLayout
高度是 120dp
你有 2 child LinearLayout
具有与 120dp
相同的高度,因此第二个 LinearLayout
到可见
解决方案
将您的根 LinearLayout
更改为 android:layout_height="wrap_content"
它会起作用
试试这个
<LinearLayout
android:id="@+id/kanji"
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="horizontal"
android:background="@drawable/rounded_corner_2"
android:layout_margin="0dp">
<TextView
android:layout_width="80dp"
android:layout_height="match_parent"
android:text="漢"
android:textColor="@color/green"
android:gravity="center"
android:textSize="70sp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/rounded_corner_2"
android:layout_margin="10dp"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="漢字"
android:textColor="@color/green"
android:textSize="20sp"
android:gravity="left"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="15dp"
android:text="漢字"
android:textColor="@android:color/darker_gray"
android:textSize="10sp"
android:gravity="left"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ProgressBar
android:layout_width="160dp"
android:layout_height="match_parent"
style="?android:attr/progressBarStyleHorizontal"
android:outlineSpotShadowColor="@color/green"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="end"
android:text="100/140"
android:textColor="@android:color/darker_gray"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/goi"
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="horizontal"
android:background="@drawable/rounded_corner_2"
android:layout_margin="0dp">
<TextView
android:layout_width="80dp"
android:layout_height="match_parent"
android:text="漢"
android:textColor="@color/green"
android:gravity="center"
android:textSize="70sp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/rounded_corner_2"
android:layout_margin="10dp"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="漢字"
android:textColor="@color/green"
android:textSize="20sp"
android:gravity="left"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="15dp"
android:text="漢字"
android:textColor="@android:color/darker_gray"
android:textSize="10sp"
android:gravity="left"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ProgressBar
android:layout_width="160dp"
android:layout_height="match_parent"
style="?android:attr/progressBarStyleHorizontal"
android:outlineSpotShadowColor="@color/green"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="end"
android:text="100/140"
android:textColor="@android:color/darker_gray"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
父 LinearLayout 的高度为 120px,其第一个子项也是如此。所以第一个子LinearLayout填满了父布局的所有高度。
您可以增加父 LinearLayout 的高度或使其 "wrap_content" 以便它根据其内容动态调整高度。
这是因为您的顶部布局具有固定高度
<?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="120dp"
android:background="@drawable/rounded_corner_2"
android:layout_margin="10dp"
android:orientation="vertical">
更新为
<?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="wrap_content"
android:background="@drawable/rounded_corner_2"
android:layout_margin="10dp"
android:orientation="vertical">
您的父LinearLayuot 和子LinearLayouts 的高度为120dp。您需要更改子布局的高度以适应父布局
您可以使用指令 <include></include>
,但我建议在约束布局上进行实施