Android Material加载进度条 Android Material加载进度条制作代码
chenzheng8975 人气:0想了解Android Material加载进度条制作代码的相关内容吗,chenzheng8975在本文为您仔细讲解Android Material加载进度条的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Android,Material加载进度条,Material进度条,下面大家一起来学习吧。
最近看了几款APP的加载进度都是这种风格,感觉还不错,在网上找了一些资料,自己小练兵了一把:
主要运用的开源框架:
/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();
结束刷新:mPtrFrameLayout.refreshComplete();
mPtrFrameLayout.setPinContent(true);这里可以根据个人喜好设置true或者false,true则在刷新的时候,将布局里的内容固定不动,false则是在刷新的时候进度条会将布局内容挤下来。
监听ListView是否滑动到底部,如果到达底部,则显示底部加载更多的进度条。
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(){ @Override public 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 } });
加载全部内容