我有一個圓形的自定義狀態,我希望它改變其顏色,但我得到的形狀爲正方形不是圓的,因爲我想如何將顏色更改動畫賦予自定義形狀?
這裏是我的形狀:
<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)的解決方案 –