前面写了4篇自定义控件的博客,并且开通了一个专栏,把4篇文章添加到专栏中了,耐心等待博客专栏的徽章出现,奈何等了几周后还是没有出现,后来发现至少需要5篇文章才能出现专栏徽章,于是有了这篇仿我大京东快递小哥的下拉刷新。
直接上图先!
分析
这个下拉刷新效果分为两个部分:
step1:快递小哥和快递包裹的缩放效果,看上去就像是快递小哥跑过来一手拿过快递的样子
step2:快递小哥拿到包裹后,开启暴走模式!玩命送快递
PS:不得不赞一下京东的快递,真的很快!
step1
好了马屁拍完了,我们先来看一看第一部分的效果是怎么实现的。首先快递小哥和包裹是两张图片
我们看到快递小哥是从小变大的,快递包裹也是从小变大的,所以我们要自定义一个控件,就起名为FirstStepView.java吧
public class FirstSetpView extends View{
private Bitmap goods;
private Bitmap people;
private Bitmap peopleWithGoods;
private int measuredWidth;
private int measuredHeight;
private float mCurrentProgress;
private int mCurrentAlpha;
private Paint mPaint;
private Bitmap scaledPeople;
private Bitmap scaledGoods;
public FirstSetpView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public FirstSetpView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public FirstSetpView(Context context) {
super(context);
init();
}
private void init(){
//包裹bitmap
goods = BitmapFactory.decodeResource(getResources(), R.mipmap.app_refresh_goods_0);
//快递小哥bitmap
people = BitmapFactory.decodeResource(getResources(), R.mipmap.app_refresh_people_0);
//这是后面动画中的最后一张图片,拿这张图片的作用是用它的宽高来测量
//我们这个自定义View的宽高
peopleWithGoods = BitmapFactory.decodeResource(getResources(), R.mipmap.app_refresh_people_3);
//来个画笔,我们注意到快递小哥和包裹都有一个渐变效果的,我们用
//mPaint.setAlpha来实现这个渐变的效果
mPaint = new Paint();
//首先设置为完全透明
mPaint.setAlpha(