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

  • 13
  • 0
  • 约3.37万字
  • 约 43页
  • 2018-06-28 发布于湖北
  • 举报
—————————————————————————————PAGE \* MERGEFORMAT1新闻客户端讲师:杨光福微博:/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_拖动到底部显示加载更多布局/** * 当滚动状态改变的时候触发此方法 * */ @Override public void onScrollStateChanged(AbsListView view, int scrollState) { //当停止滚动时或者惯性滚动时,ListView的最后一个显示的条目:getCount()-1 if(scrollState == SCROLL_STATE_IDLE||scrollState == SCROLL_STATE_FLING){ if(getLastVisiblePosition() ==(getCount()-1)){ //滑动到最后一个可以看到的Item System.out.println(滑动到最后一个可以看到的Item); isLoadingMore = true; //把底部加载显示 footerView.setPadding(0, 0, 0, 0); setSelection(getCount()); //调用 if(mOnRefreshListener !=null){ mOnRefreshListener.onLoadingMore(); } } } } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } /** * 自定义刷新接口 * */ public interface OnRefreshListener{ /** * 当下拉刷新的时候回调这儿方法 */ public void onPullDo

文档评论(0)

1亿VIP精品文档

相关文档