-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgressButton.java
55 lines (46 loc) · 1.5 KB
/
ProgressButton.java
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
package net.oschina.app.view;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.Button;
/**
* Created by Administrator on 2016/6/25.
*/
public class ProgressButton extends Button {
private int mProgress;
private Paint mPaint = new Paint();
private Drawable mProgressDrawable;
public void setProgressDrawable(Drawable progressDrawable) {
mProgressDrawable = progressDrawable;
}
public ProgressButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ProgressButton(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mPaint.setColor(Color.BLUE);
int left = 0;
int top = 0;
int width = getMeasuredWidth();
int right = (int) (mProgress / 100f * width);
int bottom = getMeasuredHeight();
if(mProgressDrawable != null){
mProgressDrawable.setBounds(left,top,right,bottom);
mProgressDrawable.draw(canvas);
}else {
//每一次都比前一次绘制的矩形更宽,
canvas.drawRect(left, top, right, bottom, mPaint);
}
}
public void setProgress(Integer value) {
this.mProgress = value;
invalidate();
}
}