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 );
}
}
}