In the previous article, we talked about how to enable the animation of each view by opening multiple threads to refresh pages one by one, with a high overhead. A reasonable solution is provided here, that is, to generate a mask on the page and gradually refresh the content by moving the image below the mask.
Main painting class:
Package com. drawmask;
Import Android. App. activity;
Import Android. OS. Bundle;
Import Android. util. displaymetrics;
Import Android. View. view;
Import Android. View. View. onclicklistener;
Import Android. View. animation. animation;
Import Android. View. animation. translateanimation;
Import Android. View. animation. animation. animationlistener;
Import Android. widget. linearlayout;
Import Android. widget. relativelayout;
Public class drawmask extends activity implements onclicklistener {
Private linearlayout reload;
Private view mask;
/** Called when the activity is first created .*/
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
// Obtain the screen width and height
Displaymetrics dm = new displaymetrics ();
Dm = getapplicationcontext (). getresources (). getdisplaymetrics ();
Int screenwidth = DM. widthpixels;
Int screenheight = DM. heightpixels;
Relativelayout parent = (relativelayout) findviewbyid (R. Id. relativelayout01 );
// Create a new mask
Mask = new mask (this, screenwidth, screenheight );
Parent. addview (mask );
Startopenanimation ();
// Click the screen to restart the animation mask.
Reload = (linearlayout) findviewbyid (R. Id. Reload );
Reload. setonclicklistener (this );
}
Private void startopenanimation (){
Translateanimation TA = new translateanimation (0, 0, 0,500 );
Ta. setduration (2000 );
Ta. setanimationlistener (New animationlistener (){
@ Override
Public void onanimationend (animation ){
Mask. setvisibility (view. Gone );
}
@ Override
Public void onanimationrepeat (animation ){
}
@ Override
Public void onanimationstart (animation ){
}
});
Mask. startanimation (TA );
}
@ Override
Public void onclick (view v ){
Startopenanimation ();
}
}
Mask class:
Package com. drawmask;
Import Android. content. context;
Import Android. Graphics. Canvas;
Import Android. Graphics. color;
Import Android. Graphics. lineargradient;
Import Android. Graphics. paint;
Import Android. Graphics. rect;
Import Android. Graphics. shader;
Import Android. View. view;
Public class mask extends view {
Private int width, higth;
@ Override
Protected void ondraw (canvas ){
// Generate a paint brush that can draw a rectangular view with a transparent gradient.
Paint paint = new paint ();
Shader mshader = new lineargradient (0, 0, 0, 50,
New int [] {color. argb (0,255,255,255), color. White },
Null, shader. tilemode. Clamp );
Paint. setshader (mshader );
// Draw a rectangular view with a transparent gradient
Rect = new rect ();
Rect. Set (0, 0, width, higth );
Canvas. drawrect (rect, paint );
}
Public mask (context ){
Super (context );
// Todo auto-generated constructor stub
}
Public mask (context, int width, int higth ){
Super (context );
This. higth = higth;
This. width = width;
}
}