Animate the stroke width of the form

I have a thick circle with a transparent center:

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid
        android:color="@android:color/transparent"/>
    <stroke
        android:width="24dp"
        android:color="@android:color/white"/>
    <size
        android:width="72dp"
        android:height="72dp"/>
</shape>

and I would like to revive the decrease in the stroke value so that the transparent center expands like an iris.

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
        android:propertyName="????"
        android:valueFrom="24dp"
        android:valueTo="4dp"
        android:duration="750"
        />
</set>

... but I do not know what to specify as the name of the property. "strokeWidth" doesn't seem to work. I don’t even know how to do this programmatically, because GradientDrawable.setStroke () requires both width and color, and objectAnimator can only work with single parameters.

+4
source share
1 answer

, , . :

, ValueAnimator, ValueAnimator float UpdateListener, . .

:

final ShapeDrawable circle = new ShapeDrawable(new OvalShape());

//Create your shape programatically
ValueAnimator animation = ValueAnimator.ofFloat(24.0f,12.0f);
animation.setDuration(1000);
animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            circle.getPaint().setStrokeWidth((Float)animation.getAnimatedValue());
        }
});

24 12 , ValueAnimator ShapeDrawable apis, , .

+5

All Articles