Android effect View Third bounce view

Source: Internet
Author: User

Android effect View Third bounce view
dynamic I have only been doing for a long time or failed to give one, the rest of the whole by Imagination
<framelayout android:layout_width= "match_parent" android:layout_height= "match_parent" > <com            . Example.empty.FlickerTextView android:id= "@+id/flicker" android:layout_width= "Wrap_content"            android:layout_height= "Wrap_content" android:layout_gravity= "Top|left" android:text= "Happy"            Android:textcolor= "#00FF00" android:textsize= "24DP"/> <com.example.empty.flickertext Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android:layout_gravit            Y= "Bottom|right" android:alpha= "1" android:text= "Today" android:textcolor= "#0000FF" Android:textsize= "24DP"/> <com.example.empty.flikerimageview android:layout_width= "Wrap_con Tent "android:layout_height=" wrap_content "android:layout_gravity=" center "android:src=" @ Drawable/ic_launcher "/&GT </FrameLayout>


Package Com.example.empty;import Java.util.timer;import Java.util.timertask;import android.annotation.SuppressLint ; Import Android.content.context;import android.graphics.color;import android.os.handler;import android.os.Message;    Import Android.util.attributeset;import Android.widget.textview;public class Flickertextview extends TextView{    Boolean change = false;     Private Handler Handler = null;                Public Flickertextview (context context, AttributeSet Attrs) {Super (context, attrs);    TODO auto-generated Constructor stub startflicker ();            } @SuppressLint ("Handlerleak") public void Startflicker () {handler = new handler () { @Override public void DispatchMessage (Message msg) {if (change) {change = FAL                    Se SetTextColor (color.transparent);                    This is transparent, = Cannot see the text}else{change = true;        SetTextColor (color.red);        }            }        };        Timer timer = new timer (); TimerTask task = new TimerTask () {@Override public void run () {Message msg = new Me                Ssage ();            Handler.sendmessage (msg);        }        };  Timer.schedule (task,1,300); Parameters are delay (how long after execution), duration (execution interval)}}

Package Com.example.empty;import Android.content.context;import Android.graphics.canvas;import Android.util.attributeset;import Android.widget.textview;public class Flickertext extends textview{public    Flickertext (context context, AttributeSet Attrs) {        Super (context, attrs);        TODO auto-generated constructor stub    }        interface state{        static final int VISIBLE = 1;        static final int INVISIBLE = 0;    }    @Override     protected void OnDraw (canvas canvas) {         super.ondraw (canvas);        Switch (getalphastate ()) {case State        . visible:{            Setalpha (state. INVISIBLE);            break;        }        Case State. invisible:{            Setalpha (state. VISIBLE);            break;        }        }                        Postinvalidatedelayed (+);    }        public int getalphastate () {        return (int) Getalpha () = = state. INVISIBLE? State. Invisible:state. VISIBLE;            }}

Package Com.example.empty;import Java.util.timer;import Java.util.timertask;import android.content.context;import Android.os.handler;import Android.os.message;import Android.util.attributeset;import Android.widget.ImageView;    public class Flikerimageview extends ImageView {Boolean change = false;        Public Flikerimageview (context context, AttributeSet Attrs) {Super (context, attrs);    TODO auto-generated Constructor stub startflicker ();        } interface State {static final int VISIBLE = 255;    static final int INVISIBLE = 0;            } private Handler Handler = new Handler () {@Override public void DispatchMessage (Message msg) {                if (change) {change = false; Setimagealpha (state.            INVISIBLE);                } else {change = true; Setimagealpha (state.            VISIBLE);    }        }    };        public void Startflicker () {Timer timer = new Timer (); TimerTask Task= new TimerTask () {@Override public void run () {message msg = new Message ();            Handler.sendmessage (msg);        }        };    Timer.schedule (Task, 1, 300); }}

here are 3 implementations (actually two) to achieve the effect of a view flicker. Here is a brief description of the 2 ways of thinkingThe first we change the state of view by timerthe second is to redraw every once in a while through postinvalidatedelayed.
and then we change the view by 2 different ways .First, SetColor two, Setalphaof course, we can also do this through an animation (ANIM). But the principle is the same.
Here I recommend the way is postinvalidatedelayed + Setalpha to achieve but in ImageView, when you call Setalpha, the system automatically calls Invalidate (OnDraw), and your picture will always blink. Here we can only use the timer and animation to achieve

Android effect View Third bounce view

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.