如何更改起点drawrect customview android

时间:2016-09-18 10:54:27

标签: android android-custom-view

我希望通过进度绘制自定义画像这张照片:

draw rect

但是,我的问题是改变左上角到中间顶部的起点,到目前为止这是我的自定义视图:

public class RoundProgress extends View {
Path path = new Path();
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
float length;
float[] intervals = {0, 0};

public RoundProgress(Context context) {
    super(context);
    paint.setColor(Color.BLUE);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(100);
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    path.reset();
    RectF rect = new RectF(0, 0, w, h);
    float inset = paint.getStrokeWidth();
    rect.inset(inset, inset);

    path.addRoundRect(rect, 100, 100, Path.Direction.CCW);
    length = new PathMeasure(path, false).getLength();
    intervals[0] = intervals[1] = length;
    PathEffect effect = new DashPathEffect(intervals, length);
    paint.setPathEffect(effect);
}

public void setProgress(int progress) {
    PathEffect effect = new DashPathEffect(intervals, length - length * progress / 100);
    paint.setPathEffect(effect);
    invalidate();
}

@Override
protected void onDraw(Canvas canvas) {
    canvas.drawPath(path, paint);
}

}

任何人都知道如何改变它?我已经尝试改变path.move(x,y)但它不起作用。

0 个答案:

没有答案