Question

There is still a small area below the last row that is white. Why is that allowed to happen with the following code?

<?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="match_parent"
    android:orientation="vertical"
    android:background="@color/lightGray">

    <ListView
        android:id="@+id/home_listview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white" >
    </ListView>

</LinearLayout>

UPDATE: Thanks for suggestions everyone. The issue was because of something weird I was doing when inflating custom rows in getView of my adapter. I wanted the rows of my ListView to be different sizes. Well apparently, the listview was getting its total overall height based on calculating the height of the first row inflated multiplied by number of rows. This caused an issue because all my rows were not the same size. I ended up dynamically changing the height of the listview based on the height of each row added up.

Was it helpful?

Solution 3

The solution I ended up going with was to just make the ListView background color the same as the LinearLayout background color, but make each row of the ListView the color that I really wanted the ListView to be. This way if there was extra space at the bottom of the ListView because of the height being calculated incorrectly, it would just look like part of the background. Also with this solution, I don't have to worry about making a dynamic height calculation of the ListView.

OTHER TIPS

It may be the divider - try setting it to transparent (or the colour of your choice) You can also change the height:

    <ListView
        android:id="@+id/home_listview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@android:color/transparent"
        android:dividerHeight="10dp"
        android:padding="10dp" />

try to change layout_width and layout_height values to fill_parent

<ListView
        android:id="@+id/home_listview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/white" >
    </ListView>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top