先上一张美团的下拉刷新
美团
添加依赖 implementation 'com.github.runitwolf:refreshDemo:V1.0.0'
GIF.gif
1.去拿美团的图片(Emmm,我随便挑了)
image.png
主要是MeiTuanRefreshManager的实现类,定义了几种状态(静止、下拉刷新、释放刷新、正在刷新、刷新完成),稍微改造一下,基本可以满足下拉刷新的需求。
public class MeiTuanRefreshManager extends BaseRefreshManager {
private ImageView mImagView;
private TextView tv_state;
public MeiTuanRefreshManager(Context context) {
super(context);
}
@Override
public View getHeaderView() {
View inflate = mLayoutInflater.inflate(R.layout.meituan_header_refresh_layout, null, false);
mImagView = inflate.findViewById(R.id.loading);
tv_state = inflate.findViewById(R.id.tv_state);
return inflate;
}
//这个回调 只会触发一次
@Override
public void downRefresh() {
}
//释放刷新的时候 会 变成 美团的 吉祥物
@Override
public void releaseRefresh() {
mImagView.setImageResource(R.drawable.meituan_loading);
AnimationDrawable mAnimationDrawable= (AnimationDrawable) mImagView.getDrawable();
mAnimationDrawable.start();
tv_state.setText("释放刷新");
}
@Override
public void iddleRefresh() {
mImagView.clearAnimation();
mImagView.setImageResource(R.mipmap.hy9);
mImagView.setScaleX(0);
mImagView.setScaleY(0);
}
//正在刷新的状态实际上也是一个帧动画
@Override
public void refreshing() {
mImagView.setImageResource(R.drawable.meituan_loading);
AnimationDrawable mAnimationDrawable = (AnimationDrawable) mImagView.getDrawable();
mAnimationDrawable.start();
tv_state.setText("正在刷新");
}
@Override
public void downRefreshPercent(float precent) {
mImagView.setScaleX(precent);
mImagView.setScaleY(precent);
tv_state.setText("下拉刷新");
mImagView.setImageResource(R.mipmap.hy9);
}
@Override
public void overRefresh() {
mImagView.setImageResource(R.drawable.meituan_loading);
AnimationDrawable mAnimationDrawable = (AnimationDrawable) mImagView.getDrawable();
mAnimationDrawable.start();
tv_state.setText("刷新完成");
}
}
网友评论