简体   繁体   中英

Add BottomView to GridView Android

I'm creating a lazy loading on a GridView and what I need is to have a BottomView with a progress bar, but just now I've discovered that there's no BottomView for the GridView element and searching on Google I haven't found a solution.

So my question is, is it possible to add a BottomView to a GridView?

You can use last item as a view which will be used to initialising loading.

You have to add one element in getCount method

@Override
public int getCount() {
    return yourList.size() + 1;
}

And you have to override getItemType view

@Override
public int getItemViewType(int position) {

    if (position != yourList.size()) {
        return PRODUCT_ITEM_VIEW_TYPE; //0
    }
    return PROGRESS_BAR_VIEW_TYPE; //1
}

After this you have to create two different ViewHolders for these views

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final View view;
    switch (getItemViewType(position)) {
        case PRODUCT_ITEM_VIEW_TYPE:
            view == //view for standard view
            break;
        case PROGRESS_BAR_VIEW_TYPE:
            view =  //view  for progress view
            break;
        default:
            throw new IllegalArgumentException("View type : " + viewType + " is not supported.");
    }
    return view;
}

So my question is, is it possible to add a BottomView to a GridView?

Not with the standard widget. What you can do is to wrap the GridView with the layout that contains your progress bar in a RelativeLayout . With android:layout_alignBaseline="@id/id_of_gridview" , you should be able to make them overlap, at the very bottom, of the GridView itself

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM