[英]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内部缺少Linearlayout
您的根LinearLayout
高度是120dp
并且您有2个子LinearLayout
,其高度为120dp
因此第二个LinearLayout
没有空间可见
将你的根LinearLayout
hight更改为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>
但我建议在约束布局上执行实现
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.