1

我将TextViewandroid中的背景设置为饼图。我已经使用 a LayerDrawableof ArcShape(s) 这样做并将其设置为背景。这是代码:

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);

现在,我想做的是在值correctAngle变化时为这个背景设置动画。我看到的选项之一是使用ValueAnimator并从初始值转到新值,correctValue并且每次在onAnimationUpdate()回调中创建一个LayerDrawable具有更改值的新对象并将其设置为背景。其他方法可能是Drawables首先在背景中获取所有(s)(它们是ShapeDrawable(<ArcShape>)对象,然后设置弧的角度。但我想没有办法这样做。还有其他方法可以实现吗?

4

0 回答 0