[英]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. 我正在GridView上创建延迟加载,我需要的是带有进度条的BottomView,但是现在我发现GridView元素没有BottomView,并且在Google上搜索时我还没有找到解决方案。
So my question is, is it possible to add a BottomView to a GridView? 所以我的问题是,是否可以将BottomView添加到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 您必须在getCount方法中添加一个元素
@Override
public int getCount() {
return yourList.size() + 1;
}
And you have to override getItemType view 而且您必须覆盖getItemType视图
@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 之后,您必须为这些视图创建两个不同的ViewHolders
@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? 所以我的问题是,是否可以将BottomView添加到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
. 您可以做的是将GridView
的布局包装在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 使用android:layout_alignBaseline="@id/id_of_gridview"
,您应该能够使它们在GridView
本身的最底部重叠。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.