我有一个圆形的自定义状态,我希望它改变其颜色,但我得到的形状为正方形不是圆的,因为我想如何将颜色更改动画赋予自定义形状?
这里是我的形状:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#666666"/>
<size
android:width="120dp"
android:height="120dp"/>
在我的布局:
<ImageView
android:id="@+id/rgb_led"
android:visibility="gone"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/round_led"
android:layout_centerHorizontal="true" />
代码
:
ledImageView.setVisibility(View.VISIBLE);
int colorFrom = getResources().getColor(colorFromId);
int colorTo = getResources().getColor(colorToId);
colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
colorAnimation.setDuration(duration);
colorAnimation.setRepeatCount(ValueAnimator.INFINITE);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
ledImageView.setBackgroundColor((int) animator.getAnimatedValue());
}
});
colorAnimation.start();
但我得到一个闪烁的方形不是圆形!?
编辑:
我实际上想动画一个圆形的图像,以获得闪烁的彩色光的效果,可以改变颜色和闪烁持续时间。
干杯。
我建议你看一下这个【答案】(https://stackoverflow.com/a/3208800/113012)的解决方案 –