Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add extra space inside at the bottom of a GridView

I need help to add a space inside a GridView at the bottom of it. This Space should be below the last Element of the GridView, inside of it. This space shouldn't work like a margin to the next element, it should be only visible, when the user scrolles to the bottom of the GridView. The reason for this is an ad banner which partly covers the bottom of the GridView. Besides this obstruction, the user should still be able to see the whole content of the GridView, that's why the space at the bottom of the GridView is needed.

left: ad (blue) covers part of GridView elements (orange); right: ad covers the space in the bottom of the GridViewleft: ad (blue) covers part of GridView elements (orange); right: ad covers the space in the bottom of the GridView

same approach but with space at the bottom

Example, how it will look like, just imagine that the space is at the bottom, not at the top.

So far I tried to work with the Padding and Marging Variables for Bottom, but they are not the right variables for the problem. I also searched through stackoverflow, I found some similar questions like: Add extra space to bottom of a GridView or ListView or: Adding a footer View to a multi-column GridView in Android?. But the solutions doesn't seem to fit my case and furthermore I am searching for a solution inside the layout file and not inside the source code (if there is any of course).

Your help is very much appreciated.

like image 419
Elementary Avatar asked Sep 11 '14 13:09

Elementary


Video Answer


1 Answers

To achieve that you want you need to add a bottom padding to your GridView but also disable clipToPadding behavior. Try the XML code below:

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

You can also do it from code if you want. The benefit is that you can compute the offset dynamically in code:

gridView.setPadding(int left, int top, int right, int bottom);
gridView.setClipToPadding(false);

Note: Without disabling the clipToPadding behavior you will end up with persistent empty area on the bottom of your GridView, so disabling it is very important.


Bonus: Here is also a nice link about using clipToPadding parameter in ListView or GridView: https://plus.google.com/+AndroidDevelopers/posts/LpAA7q4jw9M

like image 65
Maciej Ciemięga Avatar answered Oct 12 '22 11:10

Maciej Ciemięga