Android uses the paint mask to display information row by row

Source: Internet
Author: User

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

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.