Add flickering text in the middle of the Activity screen,

Source: Internet
Author: User

Project needs to be added to the PC version of the similar effect. For example, in employee Practice mode, several Chinese characters are constantly flashing in the middle of the screen: "Practice mode ".


Maybe this method is not good, but I did. It is assumed that the activity screen is complex.


The code is actually very simple and directly pasted.

Package com. example. sqlitepagetest; import android. app. activity; import android. graphics. color; import android. OS. bundle; import android. OS. handler; import android. OS. message; import android. view. gravity; import android. view. view; import android. widget. button; import android. widget. frameLayout; import android. widget. linearLayout. layoutParams; import android. widget. textView ;/***

*

* 11:52:59 PM ** @ auther dalvikCoder */public class Activity2 extends Activity {Button btn; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity2); btn = (Button) findViewById (R. id. btntrain); addAliveText ();} private TextView aliveText;/** text flashing thread **/private TextThread textThread = null; private void addAliveText () {aliveText = new TextView (this); aliveText. setText ("Exercise Mode"); aliveText. setTextColor (Color. RED); aliveText. setTextSize (50); aliveText. setBackgroundColor (Color. TRANSPARENT); aliveText. setGravity (Gravity. CENTER | Gravity. CENTER_VERTICAL); FrameLayout. layoutParams p = new FrameLayout. layoutParams (LayoutParams. MATCH_PARENT, LayoutParams. MATCH_PARENT, Gravity. CENTER | Gravity. CENTER_VERTICAL); this. addContentView (aliveText, p); if (textThread = null) {textThread = new TextThread (); textThread. start () ;}/ *** @ author Exercise Mode text flashing */public class TextThread extends Thread {@ Overridepublic void run () {do {try {Thread. sleep (1*1000); // The Message is flashed once every 1 s msg = new Message (); msg. what = 6; timeHandler. sendMessage (msg);} catch (InterruptedException e) {e. printStackTrace () ;}} while (true) ;}} private Handler timeHandler = new Handler () {@ Overridepublic void handleMessage (Message msg) {super. handleMessage (msg); switch (msg. what) {case 6: if (aliveText. getVisibility () = View. VISIBLE) {aliveText. setVisibility (View. INVISIBLE);} else if (aliveText. getVisibility () = View. INVISIBLE) {aliveText. setVisibility (View. VISIBLE) ;}break ;}}};}


When the activity is complex and the user clicks the screen to respond to the event, the flashing text does not affect event processing. Unless he is specially added with event listening.


Mobile phones use app treasure. The actual effect is faster and it feels better.


You can compare the differences between the two methods:


This. addContentView (aliveText, p );

SetContentView (R. layout. activity2 );




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.