sivaraj
sivaraj

Reputation: 1867

How to add text or button in gridview end in android

i am using grid view for display images,so i want to add text or button ie "Next Images" gridview end,its like footer of grid view,anybody knows please give answer to me...

Thanks all

Upvotes: 2

Views: 5332

Answers (2)

Hakan Ozbay
Hakan Ozbay

Reputation: 4719

You're going to have to use the Merge Layout thats proposed in the Android Dev guide.

I have tried this out briefly using a GridView and TextView and has worked Pretty well.

here is my code for merge.xml :

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android = "http://schemas.android.com/apk/res/android" >

<GridView 
       android:id = "@+id/gridview"
       android:layout_height = "fill_parent"
       android:layout_width = "fill_parent"
       android:columnWidth = "90dp"
       android:numColumns = "auto_fit"
       android:verticalSpacing = "10dp"
       android:horizontalSpacing = "10dp"
       android:stretchMode = "columnWidth"
       android:gravity = "center"
       android:background="#FFFFFF"
/>

<TextView
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="20dip"
        android:layout_gravity="center_horizontal|bottom"

        android:padding="12dip"

        android:background="#AA000000"
        android:textColor="#ffffffff"

        android:text="Want to see more?" />
</merge>

In your Activity class you should do the following:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.merge);

        GridView gridView = (GridView) findViewById(R.id.gridview);
        gridView.setAdapter(new ImageAdapter(this));

note: ImageAdapter is a custom adapter used to display images. Now Using some random pictures you can generate the following view.

Obviously you would need to change the TextView to some sort of a button and maybe disable any scrolling in the GridView for your idea to work well.

Upvotes: 3

CommonsWare
CommonsWare

Reputation: 1007554

Put it below the GridView. Have the GridView and the "text or button" be inside some container (RelativeLayout, LinearLayout, etc.) and position them accordingly.

Upvotes: 0

Related Questions