This article describes the Android software startup animation and animation after the end of the implementation of the jump. Share to everyone for your reference, specific as follows:
I wrote a small program, software startup, first show a few pictures, every 3 seconds to display a picture, show the end of the jump to the home page
1. The picture Carousel uses gallery, the usage is very simple
Galleryadapter adapter = new Galleryadapter (this, mIds);
Mgallery.setadapter (adapter);
Galleryadapter is a custom adapter
public class Galleryadapter extends Baseadapter {private context mcontext;
private int mimageheight;
Private int[] MIds;
Public Galleryadapter (context context, int[] ids) {This.mcontext = context;
This.mids = IDs;
Init ();
private void Init () {mimageheight = Px2dip (Mcontext, Getscreenheight (mainactivity.this));
@Override public int GetCount () {return mids.length;
@Override public Object getitem (int position) {return position;
@Override public long getitemid (int position) {return position; @Override public View getview (int position, View Convertview, ViewGroup parent) {Final ImageView ImageView = new
ImageView (Mcontext);
if (position < mids.length) {int imageid = mids[position]; Imageview.setscaletype (ImageView.ScaleType.CENTER_CROP)//Set picture centered Imageview.setlayoutparams (new
Gallery.layoutparams (Gallery.LayoutParams.FILL_PARENT, mimageheight)); Bitmap Bitmap = Readbitmap (Mcontext, IMAGeid////////////////////////////////
Overridependingtransition (r.anim.push_in, r.anim.push_out);//Picture Toggle Animation} return ImageView;
}
}
2. Set picture switching time using timer timer
Timer timer = new timer ();
Timer.schedule (Task, 3000, 3000); Toggle a picture every 3 seconds
private timertask task = new TimerTask () {@Override public
void run () {message Message
= new Message ();
message.what = 0;
index = Mgallery.getselecteditemposition ();
Handler.sendmessage (message);
index++;
if (index = = mids.length-1) {
this.cancel ();
MainActivity.this.finish ();
Intent Intent = new Intent (mainactivity.this, test.class);
StartActivity (intent);
}
}
;
You cannot update the UI directly in a task, so send a message to the main thread with Handler
private Handler Handler = new Handler () {
@Override public
Void Handlemessage (Message msg) {
super.handlemessage (msg);
Switch (msg.what) {case
0:
mgallery.setselection (index);
break;
Default: Break;}}
;
3. Read local resource picture
public static Bitmap Readbitmap (context context, int resid) {
bitmapfactory.options opt = new Bitmapfactory.options () ;
Opt.inpreferredconfig = Bitmap.Config.RGB_565;
Opt.inpurgeable = true;
Opt.ininputshareable = true;
Get resource picture
InputStream is = Context.getresources (). Openrawresource (RESID);
Return Bitmapfactory.decodestream (IS, null, opt);
}
Full instance code code click here to download the site.
I hope this article will help you with the Android program.