Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to create Footer for Gridview in Android

See below layout. I am unable to put footer button below a GridView. Any help will be appreciate.

When Gridview fill in the screen Button is not displayed.

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
 >

<GridView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gridview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:columnWidth="90dp"
    android:gravity="center"
    android:horizontalSpacing="10dp"
    android:numColumns="auto_fit"
    android:stretchMode="columnWidth"
    android:verticalSpacing="10dp" />

<Button
    android:id="@+id/button1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/gridview"
    android:text="Load More Images" />

 </RelativeLayout>
like image 637
Dhaval Khant Avatar asked Jan 16 '12 06:01

Dhaval Khant


2 Answers

I have been keeping searching for a long time for a GridView which allows us to addFooterView and addHeaderView like ListView.

It's a post 2 years ago. I come here by following the link in google search result. I don't know weather this problem has been solved or not.

If not, here is a library which may be helpful. https://github.com/liaohuqiu/android-GridViewWithHeaderAndFooter.

It's very simple:

GridViewWithHeaderAndFooter gridView = (GridViewWithHeaderAndFooter) v.findViewById(R.id.ly_image_list_grid);

LayoutInflater layoutInflater = LayoutInflater.from(this);
View headerView = layoutInflater.inflate(R.layout.test_header_view, null);
View footerView = layoutInflater.inflate(R.layout.test_footer_view, null);
gridView.addHeaderView(headerView);
gridView.addFooterView(footerView);

Here is a screen snapshot:

Screen Shot

Hope this would be helpful. Good luck!

like image 198
srain Avatar answered Sep 21 '22 06:09

srain


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
>  

 <GridView android:layout_height="match_parent" android:id="@+id/all_workouts_list" 
  android:columnWidth="90dp"
    android:gravity="center"
    android:horizontalSpacing="10dp"
    android:numColumns="auto_fit"
    android:stretchMode="columnWidth"
    android:verticalSpacing="10dp"  android:cacheColorHint="#ffffffff" 
    android:layout_width="match_parent" 
   android:layout_above="@+id/add_workout_all_workout_list"></GridView>

<Button android:layout_width="wrap_content"      
 android:id="@+id/add_workout_all_workout_list" android:layout_height="wrap_content" 
 android:text="Add Workout" android:layout_alignParentBottom="true"  
 android:layout_alignParentLeft="true"></Button>

</RelativeLayout>  

Works fine for me

like image 40
deepak Sharma Avatar answered Sep 17 '22 06:09

deepak Sharma