Overlay an ActionBar with a GridView add-on or a custom GridView to display the entire first image?

I have activity with a gridview inside it. ActionBar is set to blend mode.

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

How to add a registration to the interior of the GridView so that it is initialized so that you can see the entire first image? Or is there another way? For example, how do I extend the GridView extension to create one that has a built-in custom dynamic break in front?

example

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

edit: I hide the ActionBar whenever the user scrolls at a certain speed or past a certain level.

+4
source share
3 answers

Use ViewTreeObserver.OnGlobalLayoutListener in your activity or snippet to determine the number of columns your GridView will display (assuming that it depends on screen size and orientation), and then use this number in your Adapter implementation. In getView() , if position less than the number of columns, return an empty view whose height matches the action line, otherwise bind your data as you normally would.

There is a great example that does exactly what you want in the sample application “Displaying Bitmaps Effectively”: https://developer.android.com/training/displaying-bitmaps/display-bitmap.html

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

+4
source

Try adding android:layout_marginTop="?android:attr/actionBarSize" to the parent element of the GridView or to the GridView itself if it does not.

This will push your layout so that it is below the ActionBar .

Edit

You may want to use ListView instead of GridView . Of course, you can easily achieve this effect by creating a fake title and then calling ListView.addHeaderView . You cannot do the same with a GridView . What you are talking about can be done using the GridView , but you will need to subclass it and change a bit.

Headline

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingTop="?android:attr/actionBarSize" /> 
+4
source

Having an ActionBar in blend mode, the following works for me:

 <GridView android:layout_width="match_parent" android:layout_height="match_parent" android:paddingTop="?android:attr/actionBarSize" android:clipToPadding="false" android:numColumns="auto_fit" android:columnWidth="120dp" android:verticalSpacing="8dp" android:horizontalSpacing="8dp" android:stretchMode="columnWidth" android:gravity="center" android:id="@+id/gridLibrary" /> 

The most important lines are here: android: paddingTop and android: clipToPadding . In my application, when I open an action using the gridview above, the first line is completely visible. Then, when I scroll down, the ActionBar hides and the gridview fills the entire screen.

+3
source

All Articles