Wednesday, February 20, 2019

Blinking Android view

A blinking view can attract user’s attention.
If we want some view like button or textView blink, we have two ways to do.
Assume that it’s a textView, in xml file, you add some lines of code.
<blink
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" >
    <TextView
        android:id="@+id/tv"
        android:layout_width="200dp"
        android:layout_height="50dp"
         android:layout_marginTop="15dp"
        android:layout_gravity="center_horizontal"
        android:text="TextView blinking"
        android:textColor="#800000"      
        android:textSize="20dp" />
   </blink>
Second way we do in code, below findViewByid, add these lines.
Animation mAnimation = new AlphaAnimation(1, 0);
mAnimation.setDuration(200);
mAnimation.setRepeatCount(Animation.INFINITE);
mAnimation.setRepeatMode(Animation.REVERSE); tv.startAnimation(mAnimation);
To make it blink faster, change value of line

mAnimation.setDuration(200); to smaller value.

No comments:

Post a Comment