Adding a header and footer to a gridview in Android

I am trying to create user profile pages in my Android application with the following functions: - title - gridview showing a bunch of photos from this user - footer (upload icon when the application loads more photos in gridview) - the title should move along with gridview

In other words, the user interface on the profile page will be very similar to the user interface on the Instagram user profile page.

The problem is that gridview does not support headers and footers.

Any solutions or libraries that I could use to provide the desired user experience?

+1
source share
1 answer

Just use multiple RelativeLayouts.

Create your header layout (50dp or something else) matching the parent top. Then create a second layout aligned at the bottom of the page (this will be your footer). Then add another layout below the β€œheader” and β€œabove” the footer that your GridView will contain.

It should look like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:id="@+id/header" android:layout_width="match_parent" android:layout_height="50dp" android:layout_alignParentTop="true" > /* ANYTHING YOU WANT IN YOUR HEADER */ </RelativeLayout> <RelativeLayout android:id="@+id/gridview" android:layout_width="match_parent" android:layout_height="fill_parent" android:layout_below="@+id/header" android:layout_above="@+id/footer" > /* GRIDVIEW HERE */ </RelativeLayout> <RelativeLayout android:id="@+id/footer" android:layout_width="match_parent" android:layout_height="50dp" android:layout_alignParentBottom="true" > /* ANYTHING YOU WANT IN YOUR FOOTER */ </RelativeLayout> </RelativeLayout> 

Hope this helps.

+4
source

Source: https://habr.com/ru/post/976979/


All Articles