主要运用的开源框架:
/ViewPagerIndicator_library 主要就是tab页切换指示器
/ptr-lib 进度条 下载地址:https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh
一、使用方法
布局文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/bg_color" android:orientation="vertical" ><in.srain.cube.views.ptr.PtrFrameLayout xmlns:cube_ptr="http://schemas.android.com/apk/res-auto" android:id="@+id/material_style_ptr_frame" android:layout_width="match_parent" android:layout_height="match_parent" cube_ptr:ptr_duration_to_close="100" cube_ptr:ptr_duration_to_close_header="100" cube_ptr:ptr_keep_header_when_refresh="true" cube_ptr:ptr_pull_to_fresh="false" cube_ptr:ptr_ratio_of_header_height_to_refresh="1.2" cube_ptr:ptr_resistance="1.7" ><ListView android:id="@+id/article_listview" android:layout_width="match_parent" android:layout_height="match_parent" android:cacheColorHint="#00000000" android:divider="@color/line" android:dividerHeight="10dp" /> </in.srain.cube.views.ptr.PtrFrameLayout></LinearLayout>在java代码中进行控件声明,设置相关参数
mPtrFrameLayout = (PtrFrameLayout) mRootView.findViewById(R.id.material_style_ptr_frame);// header final MaterialHeader header = new MaterialHeader(getActivity()); int[] colors = getResources().getIntArray(R.array.google_colors); header.setColorSchemeColors(colors); header.setLayoutParams(new PtrFrameLayout.LayoutParams(-1, -2)); header.setPadding(0, Utils.dip2px(getActivity(), 15), 0, Utils.dip2px(getActivity(), 10)); header.setPtrFrameLayout(mPtrFrameLayout);mPtrFrameLayout.setPinContent(true); mPtrFrameLayout.setLoadingMinTime(100); mPtrFrameLayout.setDurationToCloseHeader(100); mPtrFrameLayout.setHeaderView(header); mPtrFrameLayout.addPtrUIHandler(header); mPtrFrameLayout.setPtrHandler(new PtrHandler() { @Override public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) { return PtrDefaultHandler.checkContentCanBePulledDown(frame, article_listview, header); }@Override public void onRefreshBegin(final PtrFrameLayout frame) { pageNum = 1; doRequest(pageNum, true); } });手动刷新:mPtrFrameLayout.autoRefresh();
moreView = Finder.inflate(getActivity(), R.layout.loading_more_footer); moreView.setVisibility(View.GONE); article_listview = (ListView) mRootView.findViewById(R.id.article_listview); article_listview.addFooterView(moreView); adapter = new ArticleListAdapter(getActivity()); article_listview.setAdapter(adapter); article_listview.setOnItemClickListener(new OnItemClickListener() {@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Article article = (Article) adapter.getItem(position); Intent intent = new Intent(getActivity(), AppBrowserActivity.class); intent.putExtra("w_url", article.getUrl()); intent.putExtra("share_desc", article.getTitle()); intent.putExtra("share_pic", article.getPicUrl()); startActivity(intent); } }); article_listview.setOnScrollListener(new OnScrollListener(){@Overridepublic void onScrollStateChanged(AbsListView view, int scrollState){// 当不滚动时if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {// 判断是否滚动到底部if (view.getLastVisiblePosition() == view.getCount() - 1) { //加载更多功能的代码moreView.setVisibility(View.VISIBLE); pageNum++; doRequest(pageNum, false); }}}@Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { // TODO Auto-generated method stub}});以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。