扩展视图以使其父布局与动态内容相匹配

Extend a View to match its parent layout with dynamic content

我正在处理如下图所示的复杂布局结构。蓝色 Layout/View 需要随着红色布局的数量垂直增加而扩展,如第二张图片所示。是的,根据要求,紫色布局高度应该是 wrap-content(不应与父级匹配)。 当我将蓝色布局设置为匹配父级时出现问题,它占据了整个屏幕的高度。

RED布局动态增加后:

这里是drawable/circle_redxml文件

 <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape android:shape="oval">
                <solid android:color="#f1ce2a2a" />
                <corners android:radius="2dp" />
            </shape>
        </item>

    </layer-list>

主要布局xml文件看看

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:baselineAligned="false"
            android:orientation="horizontal">

            <LinearLayout
                android:id="@+id/home"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#4f56be"
                android:orientation="vertical"
                android:padding="5dp">
            </LinearLayout>
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical">
                <TextView
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_gravity="center"
                    android:background="@drawable/circle_red"
                    android:gravity="center"
                    android:textColor="#fff"
                    android:layout_margin="5dp"
                    />
                <TextView
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_gravity="center"
                    android:background="@drawable/circle_red"
                    android:gravity="center"
                    android:textColor="#fff"
                    android:layout_margin="5dp"
                    />
                <TextView
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_gravity="center"
                    android:background="@drawable/circle_red"
                    android:gravity="center"
                    android:textColor="#fff"
                    android:layout_margin="5dp"
                    />
                <TextView
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_gravity="center"
                    android:background="@drawable/circle_red"
                    android:gravity="center"
                    android:textColor="#fff"
                    android:layout_margin="5dp"/>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>