Android displays information row-by-row through threads

Source: Internet
Author: User

Today, we are investigating how to display content row by row on Android phones. This is one of the methods. alphaanimation is used to set the thread latency. The effect can be achieved, but the overhead is relatively large. The method with low overhead will be introduced in the next article.

 

Package com. display;

Import Android. App. activity;
Import Android. OS. Bundle;
Import Android. OS. Handler;
Import Android. View. view;
Import Android. View. View. onclicklistener;
Import Android. View. animation. alphaanimation;
Import Android. View. animation. animation;
Import Android. View. animation. animation. animationlistener;
Import Android. widget. Button;
Import Android. widget. textview;

Public class display extends activity {
Private textview [] TVs = new textview [7];
Private handler = new handler ();
Private button btnreload;

/** Called when the activity is first created .*/
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );

TVs [0] = (textview) findviewbyid (R. Id. textview01 );
TVs [1] = (textview) findviewbyid (R. Id. textview02 );
TVs [2] = (textview) findviewbyid (R. Id. textview03 );
TVs [3] = (textview) findviewbyid (R. Id. textview04 );
TVs [4] = (textview) findviewbyid (R. Id. textview05 );
TVs [5] = (textview) findviewbyid (R. Id. textview06 );
TVs [6] = (textview) findviewbyid (R. Id. textview07 );

Loadcontent ();

Btnreload = (button) findviewbyid (R. Id. button01 );
Btnreload. setonclicklistener (New onclicklistener (){

@ Override
Public void onclick (view v ){
Loadcontent ();
}
});

}

Private void loadcontent (){
Setinvisible ();

For (Int J = 0; j <TVs. length; j ++ ){
Final textview TV = TVs [J];
Runnable r = new runnable (){

@ Override
Public void run (){
Setanimation (TV );
}

};

 

// Sets the animation latency.

Handler. postdelayed (R, J * 1000 );
}

}

 

// Set the animation

Private void setanimation (final textview TV ){
Alphaanimation AA = new alphaanimation (0, 1.0f );
AA. setduration (1000 );
AA. setanimationlistener (New animationlistener (){

@ Override
Public void onanimationend (animation ){
TV. setvisibility (view. Visible );

}

@ Override
Public void onanimationrepeat (animation ){

}

@ Override
Public void onanimationstart (animation ){

}

});
TV. startanimation (AA );

}

Private void setinvisible (){
For (INT I = 0; I <TVs. length; I ++ ){
TVs [I]. setvisibility (view. Invisible );
}

}

}

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.