Android如何将线性布局的高度设置为listview元素?

Android如何将线性布局的高度设置为listview元素?,android,android-layout,listview,android-linearlayout,Android,Android Layout,Listview,Android Linearlayout,Android如何将线性布局的高度设置为listview元素? 我使用线性布局的listview,所以我可以这样做。请帮帮我。 我怎样才能解决它? Android如何将线性布局的高度设置为listview元素? 我使用线性布局的listview,所以我可以这样做。请帮帮我。 我怎样才能解决它 <LinearLayout android:layout_width="match_parent" android:layout_hei

Android如何将线性布局的高度设置为listview元素? 我使用线性布局的listview,所以我可以这样做。请帮帮我。 我怎样才能解决它? Android如何将线性布局的高度设置为listview元素? 我使用线性布局的listview,所以我可以这样做。请帮帮我。 我怎样才能解决它

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:id="@+id/relative"
            android:orientation="vertical"
            android:background="@drawable/shap">

            <ProgressBar
                android:id="@+id/progressBar"
                android:visibility="gone"
                style="?android:attr/progressBarStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentStart="true"
                android:layout_marginBottom="51dp"
                android:layout_marginStart="147dp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:orientation="vertical"
                android:id="@+id/lout"
                android:layout_marginBottom="10dp"
                android:background="@android:color/holo_red_light"
                android:layout_height="wrap_content">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="More Related Products"
                    android:textSize="20dp"
                    android:padding="5dp"
                    android:textColor="#ffffff"
                    android:textAlignment="center"/>
            </LinearLayout>
            <ListView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/product_list"
                android:dividerHeight="1dp"
                android:focusable="true"
                android:layout_below="@+id/lout">
            </ListView>

        </LinearLayout>

你可以这样做

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/product_list"
        android:dividerHeight="1dp"
        android:focusable="true"
        android:layout_below="@+id/lout">
    </ListView>
</LinearLayout>


这将把线性布局包装到列表视图中

将listView高度设置为包装内容是错误的做法,因为它将始终调用notifydatasetchanged()。您必须使其与您的家长匹配。然后您的布局高度将与listView相同

您可以尝试以下方法:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/product_list"
        android:dividerHeight="1dp"
        android:focusable="true"
        android:layout_below="@+id/lout">
    </ListView>
</LinearLayout>

或者类似于:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        //TO DO: YOUR CONTENT HERE

    </LinearLayout>
<ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/product_list"
            android:dividerHeight="1dp"
            android:focusable="true"
            android:layout_below="@+id/lout">
        </ListView>
</LinearLayout>

//要做的事情:你的内容在这里

请分享您想要实现的设计您正在谈论的是哪种线性布局?检查相对id线性布局@rya@hasan_shaikh我想线性布局与设置高度自动作为listview元素非常混乱。哪个
线性布局
?如果设置第二个
LinearLayout
高度,则
ListView
将退出屏幕,因为父级也是
LinearLayout
。请解释问题或显示预期输出。外部
LinearLayout
将自动调整高度,使其
wrap\u内容