Add space to top and bottom of GridView

Lim Thye Chean picture Lim Thye Chean · May 17, 2014 · Viewed 12.3k times · Source

I would like to add space to the top and bottom of GridView, similar to header/footer but I only wanted to support spaces and nothing else.

Currently I am using top/bottom padding, but when scrolled the content will be cropped in the padding part.

What's the simplest solution for this? Thanks!

Answer

Elementary picture Elementary · Sep 12, 2014

If I understand you right, it should look like this:

For that an easy solution is mentioned here by Maciej: How to add extra space inside at the bottom of a GridView

You just need to add the following in your GridView Layout:

<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="50dp"
android:paddingBottom="50dp"
android:clipToPadding="false"/>

The most important part is the clipToPadding attribute which has to be set to false.

You can also see the according blog post from Google, where this solution is mentioned: https://plus.google.com/+AndroidDevelopers/posts/LpAA7q4jw9M