I have a circular Shape View in android, I want to have the Blink animation of it.
Here is my layout.xml
<View
android:id="@+id/circle"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/solid_circle"
android:layout_centerInParent="true"/>
Drawable/solid_circle.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/colorAccent"/>
</shape>
The above code will show a Circular View. I wanted the circle to be blinking. Here is the code where I use Blink Animation for the Circular View.
ObjectAnimator objAnimator = ObjectAnimator.ofInt(mCircle, "backgroundColor", Color.WHITE, ContextCompat.getColor(getApplicationContext(), R.color.colorAccent), Color.WHITE);
objAnimator.setDuration(1000);
objAnimator.setEvaluator(new ArgbEvaluator());
objAnimator.setRepeatMode(Animation.REVERSE);
objAnimator.setRepeatCount(Animation.INFINITE);
objAnimator.start();
The problem with it is , it is Blinking the Circle in the form of a rectangle, can we have the Blink Animation in the form of a Circle ? How to achieve this ?
You are animating backgroundColor
of a view, it is going to animate background which is rectangle/square
Instead you have to implement alpha
animation
So animator is :
ObjectAnimator objAnimator = ObjectAnimator.ofFloat(mCircle, "alpha",0f,1f);
objAnimator.setDuration(1000);
objAnimator.setRepeatMode(Animation.REVERSE);
objAnimator.setRepeatCount(Animation.INFINITE);
objAnimator.start();
I Hope this is what you want.