1
我有一個ImageView
背景設置爲drawable.circle。圓圈的行程寬度很大。我希望將該筆畫寬度設置爲在指定的持續時間內將其設置爲1dp以縮小。如果這不能用drawable完成,我也有一個customView,該路徑是一個將paint.style設置爲Stroke的圓。我想將該動畫應用於drawable.circle或customView。如何動畫視圖的筆劃寬度
CustomCirleView:
public class CustomCircle extends View {
private Path path;
private Paint paint;
float customStrokeWidth = 80;
public float getCustomStrokeWidth() {
return customStrokeWidth;
}
public void setCustomStrokeWidth(float customStrokeWidth) {
this.customStrokeWidth = customStrokeWidth;
}
public CustomCircle(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
path = new Path();
paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setAntiAlias(true);
paint.setColor(Color.parseColor("#FC6C2B"));
paint.setStrokeWidth(customStrokeWidth);
path.addCircle(getMeasuredWidth()/2, getMeasuredHeight()/2, (getMeasuredWidth()/2)-customStrokeWidth, Path.Direction.CW);
canvas.drawPath(path, paint);
}
}
感謝
動畫矢量繪圖資源讓您動畫筆畫寬度。如果需要對動畫進行更精確的控制,您可以創建自定義繪圖併爲其創建動畫,則它將比自定義View更加分離。 – BladeCoder