Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionBar overlay with GridView padding or custom GridView to show entire first image?

I have an activity with a GridView inside it. The ActionBar is set to overlay mode.

Right now, you can only see half of the first image because the ActionBar cuts it in half.

How do I add padding to the interior of the GridView so that it initializes in such a way that you can see the entire first image? Or is there another way? For example, how would I go about extending GridView to create one that has a built-in configurable, dynamic gap at the front?

example

example (although ListView instead of GridView): reddit is fun app: https://play.google.com/store/apps/details?id=com.andrewshu.android.reddit

edit: I'm hiding the ActionBar whenever the user scrolls down at a certain rate or past a certain level.

like image 762
wufufufu Avatar asked Dec 20 '22 08:12

wufufufu


1 Answers

Use a ViewTreeObserver.OnGlobalLayoutListener in your Activity or Fragment to determine the number of columns your GridView will display (presuming it varies based on screen size and orientation), then use that number in your Adapter implementation. In getView(), if position is less than the number of columns, return an empty view whose height matches the Action Bar, otherwise bind your data as you would normally.

There is an excellent example that does exactly what you want in Google's "Displaying Bitmaps Efficiently" sample application: https://developer.android.com/training/displaying-bitmaps/display-bitmap.html

Here is the relevant source code: https://android.googlesource.com/platform/development/+/master/samples/training/bitmapfun/src/com/example/android/bitmapfun/ui/ImageGridFragment.java

like image 63
Jeff Gilfelt Avatar answered Mar 03 '23 10:03

Jeff Gilfelt