如果ListView在NestedScrollView中,match_parent不适用于ListView

10 xml android listview nestedscrollview

在我的应用程序中,我正在使用它ListView,它在一个内部NestedScrollView.当我设置heightListView,以match_parent不覆盖整个屏幕.我想要ListView覆盖整个屏幕.

我的XML文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:isScrollContainer="false"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="fill_vertical"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingTop="1dp">

        <ListView
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:divider="@null" />
        </LinearLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

小智 40

将其添加到您的NestedScrollView

android:fillViewport="true"
Run Code Online (Sandbox Code Playgroud)

  • 这应该是一个答案 (3认同)

小智 -1

我不确定这会帮助你解决问题,但我用这个解决方案像你一样解决了我的问题

 <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:minHeight="@dimen/min_height"> //minimum height for listview
Run Code Online (Sandbox Code Playgroud)