自定义View仿IOS等待圈

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

/**
* Created by limxing on 16/1/7.
*/
public class LoadView extends ImageView {
private float degrees = 0f;
private Matrix max;
private int width;
private int height;
private Bitmap bitmap;

public LoadView(Context context) {
super(context);
init();
}

public LoadView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}

public LoadView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}

Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
degrees += 30f;
max.setRotate(degrees, width, height);
setImageMatrix(max);
if(degrees==360){
degrees=0;
}
}
};

private void init() {
setScaleType(ScaleType.MATRIX);
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.loading);
setImageBitmap(bitmap);
max = new Matrix();

width = bitmap.getWidth() / 2;
height = bitmap.getHeight() / 2;
Timer time=new Timer();
time.schedule(new TimerTask() {
@Override
public void run() {
handler.sendEmptyMessage(0);
}
},0,80);
}
}
分享到 评论