javaandroidandroid-layoutandroid-animationshapedrawable

Animate Android Ring Shape's sweep angle


Attempting to animate the Android Ring Shape to produce an effect similiar to the shown sequence of images.

Intended Animation

I have found the Shape Drawable type of Ring.

<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadius="75dp"
android:thickness="25dp"
android:useLevel="false">

Along with the ArcShape(startAngle, sweepAngle) method.

ShapeDrawable shape = new ShapeDrawable(new ArcShape(0, 360));     
shape.setIntrinsicHeight(100);
shape.setIntrinsicWidth(100);
shape.getPaint().setColor(Color.BLACK);

However, the problems arise from being unable to find the drawable shape's sweep angle property or the ability to create an inner radius for ArcShape.

I am attempting to produce a smooth animation.


Solution

  • Useful material: Android: looking for a drawArc() method with inner & outer radius

    Using PorterDuff Clear mode the inner can be "removed", leaving a doughnut shape. You can then use the Arc's sweep angle by redrawing through extending the Animation class.