簡體   English   中英

其他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內部缺少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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM