I am setting the background of a TextView
in android as a pie diagram. I have used a LayerDrawable
of ArcShape
(s) to do so and set it as the background. Here is the code for that:
final ShapeDrawable arcGreen = new ShapeDrawable(new ArcShape(-90, correctAngle));
arcGreen.getPaint().setColor(ContextCompat.getColor(this, R.color.feedback_score_3));
final ShapeDrawable arcRed = new ShapeDrawable(new ArcShape(-90 + correctAngle, 360 - correctAngle));
arcRed.getPaint().setColor(ContextCompat.getColor(this, R.color.feedback_score_1));
final Drawable[] layer = {arcGreen, arcRed, mask};
final LayerDrawable ld = new LayerDrawable(layer);
mSvaraLayout.getChildAt(i).setBackground(ld);
Now, what I want to do is to animate this background when the value of correctAngle
changes. One of the options that I see is to use ValueAnimator
and go from the initial value to the new correctValue
and each time inside the onAnimationUpdate()
callback I create a new LayerDrawable
object with the changed values and set it as a background. Other way could have been to get all the Drawables
(s) in the background first(which are the ShapeDrawable(<ArcShape>)
objects and then set the angles of the arcs. But I guess there is no way to do so. Is there any other way to achieve this?