Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Empty Space to End of ListView

Tags:

I have a ListView that with alphabetical headers for each letter. I also have an index function that brings the letter headers to the top of the screen.

My problem is when I reach the end of the list setSelection is unable to bring the last few headers to the top because it will not scroll past the end of the list.

My question is this: Is there a way to add a blank space to the end of the screen dependent on screen size? I would like to scroll until the last item in the list is at the top of the listView.

like image 631
Josh Avatar asked Oct 17 '10 14:10

Josh


1 Answers

The easiest way to add space is to add padding in xml and set clipToPadding:"false".

For RecyclerView

<android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent" android:paddingTop="20dp" android:paddingBottom="20dp" android:clipToPadding="false"/> 

For ListView

<ListView android:layout_width="match_parent" android:layout_height="match_parent" android:paddingTop="20dp" android:paddingBottom="20dp" android:clipToPadding="false"/> 

And same goes for the ScrollView

<ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:paddingTop="20dp" android:paddingBottom="20dp" android:clipToPadding="false"/> 

This specifically adds the blank space to top and bottom but hide the space when you scroll the view.

like image 158
Hemant Shori Avatar answered Sep 19 '22 09:09

Hemant Shori