Today, I want to do a task, ask for the picture button to switch, and click the corresponding event. Click to open the image. several lines of fonts are displayed on the left of the image, which are delayed. The main code is attached below. Main. xml
The following code is required for latency processing:
new Handler().postDelayed(new Runnable(){ public void run() { //execute the task } }, delay);
The java code MainActivity. java is as follows:
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) extends View06); 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 the resource image start. setImageBitmap (bmp); txtview01.setText (open the serial port ...); new Handler (). postDelayed (new Runnable () {public void run () {// execute the task txtview02.setText (open ...);}}, 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 txtview04.setText (Open C ...);}}, 1500); isBrewing = true;} // stop public void stopView () {Bitmap bmp = BitmapFactory. decodeResource (getResources (), R. drawable. blue); // open the resource image start. setImageBitmap (bmp); txtview01.setText (); txtview02.setText (); txtview03.setText (); partial (); txtview06.setText (); isBrewing = false ;}}
The following page is displayed after running:
, Click the blue image,