尚硅谷-杨光福-北京新闻day.docxVIP

  • 22
  • 0
  • 约3.01万字
  • 约 43页
  • 2018-07-07 发布于湖北
  • 举报
新闻客户端讲师:杨光福微博:/321chinavideo Day41_自定义ListView(加载更多)-4201_添加角布局 1_初始化和隐藏代码在RefreshListView构造方法中调用/** * 添加角布局 * @param context */private void initFooterView(Context context) {View footerView = View.inflate(context, R.layout.refresh_listview_footer, null);//隐藏代码footerView.measure(0, 0);int footerViewHeight = footerView.getMeasuredHeight();footerView.setPadding(0, -footerViewHeight, 0, 0);this.addFooterView(footerView);}2_布局文件refresh_listview_footer.xml ?xml version=1.0 encoding=utf-8?LinearLayout xmlns:android=/apk/res/android android:layout_width=match_parent android:layout_height=wrap_content android:gravity=center android:orientation=horizontal ProgressBar android:layout_margin=5dip android:layout_width=wrap_content android:layout_height=wrap_content android:indeterminateDrawable=@drawable/custom_progressbar / TextView android:layout_marginLeft=10dip android:layout_width=wrap_content android:layout_height=wrap_content android:text=加载更多中... android:textColor=#ff0000 android:textSize=25sp / /LinearLayout 02_拖动到底部的时候显示角1_拖动到底部显示加载更多布局/** * 当滚动状态改变的时候触发此方法 * */@Overridepublic void onScrollStateChanged(AbsListView view, int scrollState) {//当停止滚动时或者惯性滚动时,ListView的最后一个显示的条目:getCount()-1if(scrollState == SCROLL_STATE_IDLE||scrollState == SCROLL_STATE_FLING){if(getLastVisiblePosition() ==(getCount()-1)){//滑动到最后一个可以看到的ItemSystem.out.println(滑动到最后一个可以看到的Item);isLoadingMore = true;//把底部加载显示footerView.setPadding(0, 0, 0, 0);setSelection(getCount());//调用if(mOnRefreshListener !=null){mOnRefreshListener.onLoadingMore();}}}} @Overridepublic void onScroll(AbsListView view, int firstVisibleItem,int visibleItemCount, int totalItemCount) {} /** * 自定义刷新接口 * */public interface OnRefreshListener{/** * 当下拉刷新的时候回调这儿方法 */public void onPullDownRefresh();/** * 当加载更多的时候回调这个方法 */public void onLoadingMore();}/** * 当数据请求成功或者失败的时候,状态还原 */public void onRefreshFinish(boolean isSuccess){//判断是否是加载更多if(isLoadingMore){footerView.setPadding(0, -footerViewHeight, 0, 0);isLoadingMore = false;}else{

文档评论(0)

1亿VIP精品文档

相关文档