android自定义通用下拉刷新
2016-03-02 20:19
453 查看
这几天将自己写的一个通用下拉刷新抽离了出来,单独搞了个类库,效果还是不错的,代码开源在github上面了,有兴趣的可以fork一下,当时直接写的英文介绍,懒得再写中文了,就直接复制过来了。
This widget supports almost all of the android view such as listview,webview,scrollview or more.What’s more,It’s extremely flexible and extensible.You can user your own view for the pull-refresh head.I support some
callback to you in the headview for your own animation.you just need to follow the steps below.
pull refresh common view
![](http://img.blog.csdn.net/20160302195215481)
pull refresh scrollview
![](http://img.blog.csdn.net/20160302195028273)
pull refresh listview
![](http://img.blog.csdn.net/20160302195142277)
Look,how easy it is.
support the most flexible and extandable way for you.
Here is the code of my SimpleHeader
All you need to do is to subclass the BaseHeader and override methods in the code.
warning:you should not override the onUIPositionChange method int your head view because this method is used to control the UI
control the behaviour.
Class: zalezone.pullrefresh.pullrefreshview.PullContainer
Public Methods
void setPullResistance(float resistance)
set the resistance of pulling the view.
void setPullCloseDuration(int millisecond)
set the duration of close the content.
void set headerCloseDuration(int millisecond)
set the duration of close the header.
more?to to continued..
email:1433317488@qq.com,zalecoder@gmail.com
common-pull-refresh
A widget that can achieve the function of pulling to refresh. It’s like a container which can help developer to manager the sub view.This widget supports almost all of the android view such as listview,webview,scrollview or more.What’s more,It’s extremely flexible and extensible.You can user your own view for the pull-refresh head.I support some
callback to you in the headview for your own animation.you just need to follow the steps below.
Gradle dependency
I am studying how to publish this widget to the Jcenter and the mavenCenter now,so you will see the dependency soon or later.Screenshots
Though the view of the widget is not very beautiful,this widget functions well.pull refresh common view
pull refresh scrollview
pull refresh listview
Usage
Only these simple code you need to write that you get what you want.code in your activity
PullContainer mPullContainer = (PullContainer) findViewById(R.id.base_container); SimpleHeader simpleHeader = new SimpleHeader(this); mPullContainer.setHeaderView(simpleHeader); mPullContainer.setRefreshCallBack(new RefreshCallBack() { @Override public void onRefreshBegin() { mHandler.postDelayed(new Runnable() { @Override public void run() { mPullContainer.refreshComplete(); } }, 2000); } });
code in your contentView xml
<zalezone.pullrefresh.pullrefreshview.PullContainer android:id="@+id/base_container" android:layout_width="match_parent" android:layout_height="match_parent"> <zalezone.pullrefresh.pullrefreshview.MyContent android:id="@+id/my_textview" android:layout_width="match_parent" android:layout_height="match_parent" android_custom:layoutMarginLeft="40dp" android_custom:layoutMarginRight="40dp"/> </zalezone.pullrefresh.pullrefreshview.PullContainer>
Look,how easy it is.
Customizing
I guess you are wondering to know how to use your own head view with your favourite style.Of course,I alsosupport the most flexible and extandable way for you.
draw your own head view
For convenience,I offer a simple header view for you in the sample code.You just need to draw your own head view like me.Here is the code of my SimpleHeader
/** * Created by zale on 2015/12/9. */ public class SimpleHeader extends BaseHeader { private TextView stateTV; private ImageView arrowIV; private Animation rotateAn; public SimpleHeader(Context context) { this(context, null); } public SimpleHeader(Context context, AttributeSet attrs) { super(context, attrs); init(context); } private void init(Context context) { View headView = LayoutInflater.from(context).inflate(R.layout.item_simple_headview, this); stateTV = (TextView) headView.findViewById(R.id.state); arrowIV = (ImageView) headView.findViewById(R.id.arrow_image); rotateAn = AnimationUtils.loadAnimation(context,R.anim.pull_refresh_arrow_anim); LinearInterpolator linearInterpolator = new LinearInterpolator(); rotateAn.setInterpolator(linearInterpolator); } @Override public void onUIReset(Indicator indicator) { stateTV.setText("pull to refresh"); } @Override public void onUIRefreshPerpare(Indicator indicator) { stateTV.setText("release to refresh"); } @Override public void onUIRefreshBegin(Indicator indicator) { stateTV.setText("refreshing"); if (rotateAn!=null){ arrowIV.startAnimation(rotateAn); } } @Override public void onUIRefreshComplete(Indicator indicator) { stateTV.setText("refresh complete"); arrowIV.clearAnimation(); } }
All you need to do is to subclass the BaseHeader and override methods in the code.
warning:you should not override the onUIPositionChange method int your head view because this method is used to control the UI
other custom styles
Except write the head view by yourself,you can also drive the widget performs like what you want.You are able to use these methods tocontrol the behaviour.
Class: zalezone.pullrefresh.pullrefreshview.PullContainer
Public Methods
void setPullResistance(float resistance)
set the resistance of pulling the view.
void setPullCloseDuration(int millisecond)
set the duration of close the content.
void set headerCloseDuration(int millisecond)
set the duration of close the header.
more?to to continued..
Communication
If you have some suggestions or want to join me to prefect this widget,welcome to contact me.email:1433317488@qq.com,zalecoder@gmail.com
相关文章推荐
- android布局属性详解
- Android基于回调的事件处理
- android四大组件之一Serveric
- Android设计模式之浅谈MVP
- Android基于监听的事件处理机制
- Android开发常见问题 不定期更新。开发环境Android Studio
- Android 4.4 Kitkat Phone工作流程浅析(六)__InCallActivity显示更新流程
- Android开发笔记----高德地图切换后显示白色小方框问题解决
- [Android Pro] APK
- Android Download 下载功能深入研究(二) : 速度提升之探索
- Android 框架模式 MVC 在Android中的使用
- Android开发笔记----高德地图定位
- [Android Pro] AAR and JAR
- Glide - 系列综述
- 欢迎使用CSDN-markdown编辑器
- AndroidStudio开发软件
- Android 4.4环境搭建——配置AVD模拟器
- Android开发笔记----嵌入高德地图
- Intent 传递数据
- Android 横竖屏切换