Android 如何为自定义形状提供颜色变化动画?

Android 如何为自定义形状提供颜色变化动画?,android,animation,colors,shape,Android,Animation,Colors,Shape,我有一个圆形的自定义形状,我想改变它的颜色,但我得到的形状是正方形,而不是我想要的圆形 这是我的形状: <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="#666666"/> <size android:width="120dp" android:height="120d

我有一个圆形的自定义形状,我想改变它的颜色,但我得到的形状是正方形,而不是我想要的圆形

这是我的形状:

<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">

<solid
    android:color="#666666"/>

<size
    android:width="120dp"
    android:height="120dp"/>
但我得到的是一个闪光的正方形而不是圆形

编辑:
实际上,我想制作一个圆形图像的动画,以获得闪烁的彩色灯光的效果,该灯光可以改变颜色和闪烁持续时间。

干杯。

试试这段代码,我在应用程序中使用它来显示一个循环动画:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:duration="5"
    android:toDegrees="360" >

<!--    Duration = 1 means that the rotation will be done in 1 second
    increase duration if you want to speed up the rotation-->


<shape
android:innerRadiusRatio="30"
android:shape="ring"
android:thicknessRatio="80"
android:useLevel="false">

<size
    android:height="80dp"
    android:width="80dp" />

<gradient
    android:centerColor="@android:color/transparent"
    android:centerY="0.50"
    android:endColor="#E6E6E6"
    android:startColor="#BEBEBE"
    android:type="sweep"
    android:useLevel="false" />
</shape>

</rotate>

thanx但是我试着使用ValueAnimator,我可以得到一个很好的圆形。问题是当我制作动画时,你是受欢迎的,但是我可以问一下ValueAnimator比object更能实现什么吗?1。如何实施?2.我能动态地控制它吗?开始,停止?并改变颜色和持续时间我建议你看看这个问题的解决方案
 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();  
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:duration="5"
    android:toDegrees="360" >

<!--    Duration = 1 means that the rotation will be done in 1 second
    increase duration if you want to speed up the rotation-->


<shape
android:innerRadiusRatio="30"
android:shape="ring"
android:thicknessRatio="80"
android:useLevel="false">

<size
    android:height="80dp"
    android:width="80dp" />

<gradient
    android:centerColor="@android:color/transparent"
    android:centerY="0.50"
    android:endColor="#E6E6E6"
    android:startColor="#BEBEBE"
    android:type="sweep"
    android:useLevel="false" />
</shape>

</rotate>
    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyle"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_gravity="bottom|center_horizontal"
        android:visibility="gone"
        android:indeterminate="true" >
    </ProgressBar>
ProgressBar progress = (ProgressBar) findViewById(R.id.progressBar);
// Control the size
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(80,80);
// Control position
params.gravity = Gravity.CENTER_VERTICAL| Gravity.CENTER_HORIZONTAL;
// Set new parameters and visibility
progress.setLayoutParams(params);
progress.setVisibility(View.VISIBLE);
// Set Color  
progress.getIndeterminateDrawable().setColorFilter(0xFFFF0000,android.graphics.PorterDuff.Mode.MULTIPLY);