Home » Android » android – match_parent not working for ListView, if ListView is inside NestedScrollView

android – match_parent not working for ListView, if ListView is inside NestedScrollView

Posted by: admin May 14, 2020 Leave a comment

Questions:

In my app I am using a ListView and it is inside a NestedScrollView. When I set height of the ListView to match_parent it does not cover the whole screen. I want that ListView to cover the whole screen.

My XML file:

<?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>
How to&Answers:

Add this to your NestedScrollView

android:fillViewport="true"

Answer:

android:fillViewport=”true”

This makes the list view cover the entire device screen but in case there is much data, it does not enable scrolling.
You can view its results from this image

Answer:

i am not sure this will help you problem but i fix my problem like you with this solution

 <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:minHeight="@dimen/min_height"> //minimum height for listview