Android 下拉刷新控件的使用
如上图,是下拉刷新控件,这种控件使用比较普遍,Google+、知乎等都有使用,下面介绍此控件的用法。
此控件是PullToRefreshLayout,在Github有源码:https://github.com/chrisbanes/ActionBar-PullToRefresh.git
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+' <uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout android:id="@+id/pull_refresh_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:layout_width="match_parent" android:layout_height="match_parent" /> </uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout> pullRefreshLayout = (PullToRefreshLayout) findViewById(R.id.pull_refresh_layout); ActionBarPullToRefresh.from(this) .allChildrenArePullable() .listener(new OnRefreshListener() { @Override public void onRefreshStarted(View view) { } }) .setup(pullRefreshLayout);
通过以上代码,你就可以看到默认的效果了,如果需要自定义效果,请看如下:
.... ActionBarPullToRefresh.from(this) .options(Options.create() .headerLayout(R.layout.pulltorefresh_header) .build()) .allChildrenArePullable() .....
pulltorefresh_header.xml代码如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <FrameLayout android:id="@id/ptr_content" android:layout_width="match_parent" android:layout_height="48dp" android:background="?android:attr/colorBackground"> <TextView android:id="@id/ptr_text" android:layout_width="match_parent" android:layout_height="match_parent" android:textAppearance="?android:attr/textAppearanceMedium" android:gravity="center" /> </FrameLayout> <fr.castorflex.android.smoothprogressbar.SmoothProgressBar xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@id/ptr_progress" android:layout_width="match_parent" android:layout_height="wrap_content" app:spb_stroke_separator_length="0dp" app:spb_colors="@array/refresh_pb_colors" android:minHeight="3dp"/></RelativeLayout>
自定义SmoothProgressBar的效果
<fr.castorflex.android.smoothprogressbar.SmoothProgressBar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" app:spb_sections_count="4" app:spb_color="#FF0000" app:spb_colors="@array/refresh_pb_colors" app:spb_speed="2.0" app:spb_stroke_width="4dp" app:spb_stroke_separator_length="4dp" app:spb_reversed="false" app:spb_mirror_mode="false" app:spb_interpolator="spb_interpolator_accelerate" app:spb_progressiveStart_activated="true" app:spb_progressiveStart_speed="1.5" app:spb_progressiveStop_speed="3.4" />
- android用户界面-组件Widget-画廊视图Gallery
- 安卓入门.RelativeLayout相对布局1
- android实现页面下方的Tab效果
- 笔记77-listview属性介绍
- Android中圆形和条形ProgressBar设置颜色
- Android(安卓)中的各种控件
- Android动画效果
- java引入Android(安卓)NinePatch技术的意义
- Android第四十二期 - 关于微信手势退出Activity的操作
随机推荐
-
Android权限注解
-
Android(安卓)LCD(四):LCD驱动调试篇
-
Android开发之InstanceState详解
-
Android(安卓)style 的继承
-
Android(安卓)"多方向"抽屉
-
React Native 中文版(含最新Android章节)
-
关于Android(安卓)设置监听的的四种方式
-
Android(安卓)Camera预览
-
Android开发指南(37) —— Data Backup
-
整理出15个Android很有用的代码片段