Android GridView的addFooterView对应项是什么?
ListView具有addFooterView方法,该方法对于显示加载消息非常有用。但是GridView没有这种方法。那么,如何将页脚视图添加到GridView中,如GooglePlay中所示 不,对不起,GridView不提供这种功能Android GridView的addFooterView对应项是什么?,android,gridview,Android,Gridview,ListView具有addFooterView方法,该方法对于显示加载消息非常有用。但是GridView没有这种方法。那么,如何将页脚视图添加到GridView中,如GooglePlay中所示 不,对不起,GridView不提供这种功能 如果您想要一个“ClickhereforMore”条目,我会在到达当前网格数据的末尾后延迟加载数据。您可以查看Commonware,并尝试将其调整为GridView。您可以尝试使用相对布局,放置网格视图,并使用属性android:layout\u alignPa
如果您想要一个“ClickhereforMore”条目,我会在到达当前网格数据的末尾后延迟加载数据。您可以查看Commonware,并尝试将其调整为GridView。您可以尝试使用相对布局,放置网格视图,并使用属性android:layout\u alignParentBottom=“true”创建线性布局,它将在网格视图下放置您想要的内容,这就是我认为您想要的。您可以使用无止境滚动监听器作为gridview的滚动监听器。通过使用滚动侦听器,您可以获得当前位置。当到达终点时,显示自定义加载视图;当从网络加载完成(AsyncTask或Loader已完成)时,可以隐藏加载视图
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if (mOnScrollListener != null) {
mOnScrollListener.onScroll(view, firstVisibleItem,
visibleItemCount, totalItemCount);
}
// The count of footer view will be add to visibleItemCount also are
// added to totalItemCount
if (visibleItemCount == totalItemCount) {
// If all the item can not fill screen, we should make the
// footer view invisible.
} else if (!mIsLoading
&& (firstVisibleItem + visibleItemCount >= totalItemCount)
&& mCurrentScrollState != SCROLL_STATE_IDLE) {
mIsLoading = true;
if (mOnLoadMoreListener != null) {
mOnLoadMoreListener.onLoadMore();
}
}
}
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fillViewport="true" >
<com.baidu.hao123.module.video.view.LoadMoreGridView
android:id="@+id/gv_movie_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="@null"
android:fitsSystemWindows="true"
android:horizontalSpacing="10dip"
android:listSelector="@android:color/transparent"
android:numColumns="3"
android:paddingLeft="13dip"
android:paddingRight="13dip"
android:paddingTop="10dip"
android:scrollbars="none"
android:verticalSpacing="12dip" />
</LinearLayout>
<LinearLayout
android:id="@+id/auto_load_view"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_height="wrap_content"
android:paddingTop="10dip"
android:visibility="gone"
android:paddingBottom="10dip"
android:gravity="center"
android:orientation="horizontal" >
<ProgressBar
android:id="@+id/loadingBar"
android:layout_width="23dip"
android:layout_height="23dip"
android:layout_marginRight="10dip"
android:indeterminateDrawable="@drawable/progress_small" />
<TextView
android:id="@+id/loadingText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/loading"
android:textColor="@color/color_ff555555"
android:textSize="@dimen/fontSize_middle" />
</LinearLayout>
</LinearLayout>
安卓BucketListAdapter
这是bucket list适配器的实现,类似于
您可以在Google Play应用程序中看到。它具有类似网格的布局
列表元素,优点是您仍然可以使用列表
页眉和页脚-这在标准中是不可能的
GridView
链接:您可以使用此功能,使用OnScrollListener监视滚动位置,当滚动到最后一项时,您可以控制加载视图的可见性
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if (mOnScrollListener != null) {
mOnScrollListener.onScroll(view, firstVisibleItem,
visibleItemCount, totalItemCount);
}
// The count of footer view will be add to visibleItemCount also are
// added to totalItemCount
if (visibleItemCount == totalItemCount) {
// If all the item can not fill screen, we should make the
// footer view invisible.
} else if (!mIsLoading
&& (firstVisibleItem + visibleItemCount >= totalItemCount)
&& mCurrentScrollState != SCROLL_STATE_IDLE) {
mIsLoading = true;
if (mOnLoadMoreListener != null) {
mOnLoadMoreListener.onLoadMore();
}
}
}
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fillViewport="true" >
<com.baidu.hao123.module.video.view.LoadMoreGridView
android:id="@+id/gv_movie_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="@null"
android:fitsSystemWindows="true"
android:horizontalSpacing="10dip"
android:listSelector="@android:color/transparent"
android:numColumns="3"
android:paddingLeft="13dip"
android:paddingRight="13dip"
android:paddingTop="10dip"
android:scrollbars="none"
android:verticalSpacing="12dip" />
</LinearLayout>
<LinearLayout
android:id="@+id/auto_load_view"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_height="wrap_content"
android:paddingTop="10dip"
android:visibility="gone"
android:paddingBottom="10dip"
android:gravity="center"
android:orientation="horizontal" >
<ProgressBar
android:id="@+id/loadingBar"
android:layout_width="23dip"
android:layout_height="23dip"
android:layout_marginRight="10dip"
android:indeterminateDrawable="@drawable/progress_small" />
<TextView
android:id="@+id/loadingText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/loading"
android:textColor="@color/color_ff555555"
android:textSize="@dimen/fontSize_middle" />
</LinearLayout>
</LinearLayout>
@覆盖
public void onScroll(AbsListView视图,int firstVisibleItem,
int visibleItemCount,int totalItemCount){
if(mOnScrollListener!=null){
onScroll(视图,第一个VisibleItem,
visibleItemCount、totalItemCount);
}
//页脚视图的计数将添加到visibleItemCount中,也包括
//添加到totalItemCount
如果(visibleItemCount==totalItemCount){
//如果所有项目都不能填满屏幕,我们应该
//页脚视图不可见。
}否则,如果(!加载错误
&&(firstVisibleItem+visibleItemCount>=totalItemCount)
&&mCurrentScrollState!=滚动\u状态\u空闲){
加载错误=正确;
if(mOnLoadMoreListener!=null){
mOnLoadMoreListener.onLoadMore();
}
}
}
但这并不能使它像Google Play中那样天衣无缝。他们所做的是使用一个不同的xml文件,名为something\u footer。它看起来“天衣无缝”,因为它们使样式相同。但是不在GridView中。你可以下载Google play apk,将其重命名为.zip解压,然后查看他们使用的xml文件。嗯。。。但它看起来像是在GridView中,因为滚动条包含了加载的消息项。稍后我将尝试查看Google Play的xml。我不想要“单击此处查看更多”条目。我只想显示一条“正在加载…”消息,让用户知道服务器正在请求更多的项目。这些项目可能需要一段时间才能加载。难道没有办法让一个项目跨越两列吗?谢谢你的列表适配器,我需要同样的东西。但它不支持项目按下和项目点击透明。看起来我也需要覆盖ListView来定制行为。