3

What i want is to have the gridview filling whole screen. And when you scroll it down, at the end would appear a layout with 2 buttons. Ive been reading and couldnt figure how to get it. I could fix it on the top of the screen and the bottom (over the gridview). And also trying the layout with the button wont even appear when the gridview is filled.

Ive been playing with weights, aligns, etc. But cant find whats wrong. Heres the xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background="@drawable/fondo">
    <GridView android:layout_width="fill_parent" 
        android:id="@+id/gridView1" 
        android:layout_height="wrap_content"
        android:numColumns="2"
        android:listSelector="#00000000">
    </GridView>
    <LinearLayout android:id="@+id/linearLayout"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:orientation="horizontal"
        android:layout_below="@id/gridView1">
        <ImageView android:id="@+id/botonAtras"
            android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_weight="1" 
        android:onClick="onBotonAtrasClick">
    </ImageView>
    <ImageView android:id="@+id/botonAdelante"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_weight="1" 
        android:onClick="onBotonAdelanteClick">
    </ImageView>
    </LinearLayout>
</RelativeLayout>
Duqe
  • 299
  • 1
  • 5
  • 15
  • See similar qustion: http://stackoverflow.com/questions/8876596/need-to-create-footer-for-gridview-in-android. The difference is that the other question is about a button and this one is about about a layout. – AlikElzin-kilaka Oct 31 '12 at 12:52

3 Answers3

1

As far as I can tell you can't easily do this. You can do it with a plain ListView using addFooter(), but sadly GridView doesn't have this method. Also you can't implement your own GridView because it uses a lot of private APIs.

However, there is a horrible hack used here that might work:Android Pull to refresh

Apparently it uses a LinearLayout containing the header view and the ListView and moves them both. (According to this page.) As that guy says, a lot of work for a horrible horrible hack.

The only other way I can think to do it, is to give up on GridView and use a ListView where each row is a horizontal LinearLayout. Still very hacky though.

onkar
  • 4,427
  • 10
  • 52
  • 89
Timmmm
  • 88,195
  • 71
  • 364
  • 509
-1

set LinearLayout below GridView by setting android:layout_below:"@+id/gridView" inside id/linearLayout

Shailendra Singh Rajawat
  • 8,172
  • 3
  • 35
  • 40
  • 1
    Ive been playing with this, and cant find how to do it. Only thing i could do is to make it appear at bottom of screen. But not below the gridview. – Duqe Sep 30 '11 at 22:53
  • Tried it but the GridView "swallows" the bottom layout once the GridView has enough elements to fill the screen. – AlikElzin-kilaka Oct 31 '12 at 12:54
-1

I solve this problem like this:

<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
 <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:fillViewport="true" >
        <GridView
            android:id="@+id/myGrid"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:columnWidth="60dp"
            android:gravity="center"
            android:horizontalSpacing="10dp"
            android:numColumns="3"
            android:padding="10dp"
            android:stretchMode="columnWidth"
            android:verticalSpacing="10dp" />
    </LinearLayout>

    <Button
        android:id="@+id/bacth_button"
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="2dip"
        android:layout_marginRight="2dip"
        android:layout_marginTop="2dip"
        android:text="Uninstall Selected Apps"
        android:textColor="#000000"
        android:textSize="16dip"
        android:textStyle="bold" />
</LinearLayout>

include GridView in linearlayout,then i's work as you like.

notenking
  • 418
  • 3
  • 12