Created
December 21, 2016 09:12
-
-
Save pollux-/2e97bdb68e23b338652c16753deb83c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DualProgressView extends View { | |
private int mSize; | |
private Paint mPaint; | |
private RectF mRect; | |
public DualProgressView(Context context) { | |
super(context); | |
init(); | |
} | |
public DualProgressView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
init(); | |
} | |
public DualProgressView(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
init(); | |
} | |
private void init() { | |
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); | |
mPaint.setColor(Color.RED); | |
mPaint.setStyle(Paint.Style.STROKE); | |
mPaint.setStrokeWidth(8f); | |
mPaint.setStrokeCap(Paint.Cap.BUTT); | |
mRect = new RectF(200,200,800,800); | |
} | |
@Override | |
protected void onDraw(Canvas canvas) { | |
super.onDraw(canvas); | |
canvas.drawRect(mRect,mPaint); | |
} | |
@Override | |
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | |
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | |
int xPad = getPaddingLeft() + getPaddingRight(); | |
int yPad = getPaddingTop() + getPaddingBottom(); | |
int width = getMeasuredWidth() - xPad; | |
int height = getMeasuredHeight() - yPad; | |
mSize = (width < height) ? width : height; | |
setMeasuredDimension(mSize + xPad, mSize + yPad); | |
} | |
@Override | |
protected void onLayout(boolean changed, int left, int top, int right, int bottom) { | |
super.onLayout(changed, left, top, right, bottom); | |
} | |
@Override | |
protected void onAttachedToWindow() { | |
super.onAttachedToWindow(); | |
} | |
@Override | |
protected void onDetachedFromWindow() { | |
super.onDetachedFromWindow(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment