我想知道是否有可能画一个半填充的圆形,类似于下面的图片:
如果可能的话,我希望稍后可以填充这个圆形或将其变为空心,只剩下边框,这很好,但是否有任何方法可以添加动画?例如从空心圆到半填充或完全填充的圆形,发生过渡?
提前致谢。
提前致谢。
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<gradient
android:angle="0"
android:endColor="#FF000000"
android:startColor="#00000000" />
</shape>
示例代码答案:
还可以查看此答案:https://dev59.com/sGEh5IYBdhLWcg3wXCZL#22568222
public class CircleView extends View {
public CircleView(final Context context, final AttributeSet attrs) {
super(context, attrs);
_paint = new Paint();
_paint.setColor(context.getResources().getColor(R.color.colorPrimary));
_paint.setAntiAlias(true);
_paintCenter = new Paint();
_paintCenter.setColor(Color.BLUE);
_paintCenter.setAntiAlias(true);
_timeRingSize = Utils.convertDpToPixel(context, 10);
}
@Override
protected void onDraw(final Canvas canvas) {
final float height = canvas.getHeight();
final float width = canvas.getWidth();
float radious = width > height ? height * 0.5F : width * 0.5F;
final float centerX = canvas.getWidth() * 0.5F;
final float centerY = canvas.getHeight() * 0.5F;
canvas.drawCircle(centerX, centerY, radious, _paint);
RectF rectF = new RectF();
rectF.set(centerX - radious, centerY - radious, centerX + radious, centerY + radious);
canvas.drawArc(rectF, 0, 90, true, _paintCenter);
}
private final float _timeRingSize;
private Paint _paintCenter;
private Paint _paint;
}
输出:
Drawable
,重写draw(Canvas)
方法,在canvas
对象上调用方法以制作圆形,并在需要重新绘制(由于动画)时调用invalidateSelf()
。祝你好运。 - BudiusPath#op()
方法甚至更简单。 - Mike M.