Android Latency Processing Task Example

Source: Internet
Author: User

Today to do a task, request the picture to do button switch, click the departure corresponding event. Click Open, the left side of the picture shows a few lines of fonts, these lines of fonts are time-lapse display. The main code is attached below. Here are the Main.xml

<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:orientation=" horizontal "android:layout_width=" Fill_parent "android:layout_height=" Fill_pa Rent "android:layout_weight=" 6 "> <linearlayout android:orientation=" vertical "android:layout_width = "80DP" android:layout_height= "fill_parent" android:gravity= "center" android:layout_weight= "2.5" > & Lt TextView android:id= "@+id/txtview01" android:layout_width= "Wrap_content" android:layout_height = "Wrap_content" android:text= "" android:textcolor= "#ff00" android:textsize= "20sp"/> &lt ; TextView android:id= "@+id/txtview02" android:layout_width= "Wrap_content" android:layout_height             = "Wrap_content" android:text= "" android:textcolor= "#999933" android:textsize= "20sp"/> <textview Android:id= "@+id/txtvIew03 "android:layout_width=" wrap_content "android:layout_height=" wrap_content "android:text=" "Android            Oid:textcolor= "#ff33cc" android:textsize= "20sp"/> <textview android:id= "@+id/txtview04" Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "" Android:textColor = "#993399" android:textsize= "20sp"/> </LinearLayout> <imageview android:id= "@+id/s     Tart "android:layout_width=" wrap_content "android:layout_height=" wrap_content "android:src=" @drawable/blue " android:layout_gravity= "Center" android:layout_weight= "1"/> <linearlayout android:orientation = "vertical" android:layout_width= "80DP" android:layout_height= "fill_parent" android:gravity= "center" Andro id:layout_weight= "2.5" > <textview android:id= "@+id/txtview05" android:layout_width= "WR Ap_content "Android: layout_height= "wrap_content" android:text= "android:textcolor=" #ff6666 "android:textsize=" 20SP "      /> <textview android:id= "@+id/txtview06" android:layout_width= "80DP"            android:layout_height= "Wrap_content" android:text= "android:textcolor=" #003366 "android:textsize=" 20SP "   /> </LinearLayout> </LinearLayout>


The following code is used to delay processing

New Handler (). postdelayed (New Runnable () {public        void run () {        //execute the task        }     



Java code Mainactivity.java such as the following:

Package Com.example.vieweffect;import Android.app.activity;import Android.app.actionbar;import Android.app.fragment;import Android.graphics.bitmap;import Android.graphics.bitmapfactory;import Android.os.bundle;import Android.os.handler;import Android.view.layoutinflater;import Android.view.Menu;import Android.view.menuitem;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.viewgroup;import Android.widget.imagebutton;import Android.widget.imageview;import Android.widget.textview;import Android.os.build;public class Mainactivity extends Activity {TextView txtview01; TextView txtview02; TextView txtview03; TextView txtview04; TextView Txtview05; TextView txtview06;private ImageView Start =null;protected Boolean isbrewing = false; button replacement @overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.main); txtview01= (TextView) Findviewbyid (r.id.txtview01); txtview02= (TextView) Findviewbyid (r.id.txtview02); txtview03= (TextView) Findviewbyid (r.id.txtview03); txtview04= (TextView) Findviewbyid (r.id.txtview04); txtview05= (TextView) Findviewbyid (r.id.txtview05), txtview06= (TextView) Findviewbyid (r.id.txtview06); start= (ImageView) Findviewbyid (R.id.start); Start.setonclicklistener ((New Onclicklistener () {@Overridepublic void OnClick (View v) {//              TODO auto-generated Method Stubif (V==start) {if (isbrewing) Stopview ();                        else Startview (); } }}));}             Start public void Startview () {Bitmap Bmp=bitmapfactory.decoderesource (getresources (), r.drawable.stop);//Open resource picture           Start.setimagebitmap (BMP);        Txtview01.settext ("Open serial port ..."); New Handler (). postdelayed (New Runnable () {public void run () {//execute the task tx            Tview02.settext ("Open a ...");                 }}, 500); New Handler (). postdelayed (New Runnable () {public void run () {//exeCute the Task Txtview03.settext ("Open B ...");                 }}, 1000); New Handler (). postdelayed (New Runnable () {public void run () {//execute the task tx            Tview04.settext ("Open C ...");                 }}, 1500);  Isbrewing = true;             }//Stop public void Stopview () {Bitmap Bmp=bitmapfactory.decoderesource (getresources (), r.drawable.blue);//Open resource picture           Start.setimagebitmap (BMP);        Txtview01.settext ("");        Txtview02.settext ("");        Txtview03.settext ("");                Txtview04.settext ("");        Txtview05.settext ("");        Txtview06.settext ("");  Isbrewing = false; }  }

For example: The following interface appears after execution

, after clicking on the blue picture,

Android Latency Processing Task Example

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.