0

enter image description here

Hi Guys My question is very simple

I want to add images in a row like a flowlayout or GridLayout as you can see in the Image below

Above that layout i want to add a button such that it comes in between rows. When i scroll my grid View , the button Image also scrolls respective with the gridview.

Can any one suggest me some ideas how it can be possible

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
Bora
  • 1,933
  • 3
  • 28
  • 54

1 Answers1

1

If it's always a fourth item - than must be no problem.

Impelment a GridView with android:numColumns="3"

In your Adapter implement three view types

The idea is to add two blank items in a second row and a button to the middle.

private static final int TYPE_NORMAL = 0;
private static final int TYPE_BLANK = 1;
private static final int TYPE_BUTTON = 2;


@Override
public int getViewTypeCount() {
    return 3;
}

@Override
public int getCount() {
    return yourdata.size() + 3;
}

// return your real data by skipping row with the button
@Override
public Object getItem(int position) {
    if (position > 3) {
        position += 3;
    }
    return yourdata.get(position);
}

// return your real data ID by skipping row with the button  The button probably should catch it's own onClickListemer
@Override
public long getItemId(int position) {
    if (position > 3) {
        position += 3;
    }
    return yourdata.get(position).getId();
}


@Override
public int getItemViewType(int position) {
    switch(position) {
        case 4:
        case 6:
            return TYPE_BLANK;

        case 5:
            return TYPE_BUTTON;

        default:
            return TYPE_NORMAL;
    }
}

// only your items should be clickable
@Override
public boolean isEnabled(int position) {
    return position < 4 && position > 6;
}

// nope, only your specific data items are enabled.
@Override
public boolean areAllItemsEnabled() {
    return false;
}

In yout getView method just check the item view type and inflate the proper view. For more details implementing adapters with multiple item types refer to example of ListView with section headers etc.

How to generate a ListView with headers above some sections?

http://w2davids.wordpress.com/android-sectioned-headers-in-listviews/

Community
  • 1
  • 1
Yaroslav Mytkalyk
  • 16,950
  • 10
  • 72
  • 99