Android's welcome screen with gradient animations

Source: Internet
Author: User

This is a simple example, the main function is to use a gradient animation in the Welcome interface, when the animation is finished, jump to the main interface.


First you need to create a new Anim folder under the Res folder, which is used to store the animated XML file, and the content of the gradient animation is:

<?xml version= "1.0" encoding= "UTF-8"?><!--Alpha for gradient animation duration set Animation playback Duration Fromalpha Indicates the transparency at the beginning of the animation Toalpha represents the transparency at the end of the animation      (0 means full transparency 1 means completely opaque)--><alpha xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:duration=" "    android:fromalpha=" 0.3 "    android:toalpha=" 1.0 "/>"

then we'll use Animationutils to load the animation we just defined in the Welcome screen, then play the animation, listen to the animation,

It is important to note that this class uses Layoutinflater to load the layout XML file under the RES resource, and cannot use Findviewbyid ().

Please refer to the following code for details:

Import Android.app.activity;import android.content.intent;import android.os.bundle;import Android.os.Handler; Import Android.view.layoutinflater;import Android.view.menu;import Android.view.view;import Android.view.animation.animation;import Android.view.animation.animation.animationlistener;import Android.view.animation.animationutils;import Com.bear.notes.r;import Com.bear.notes.utils.commonutil;public Class Splashactivity extends Activity {private Handler mhandler; @Overrideprotected void OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Commonutil.setnotitlebar (Splashactivity.this); Commonutil.setfullscreen (splashactivity.this);//use Layoutinflater to load activity_splash.xml view RootView = Layoutinflater.from (This). Inflate (R.layout.activity_splash, NULL);/** * Cannot use Findviewbyid (r.layout.acitivyt_ Spash) method to load * because the Setcontentview () method has not yet been called, that is, the current activity * has not been set to a view, the current Activity Root view is Null,findviewbyid () method is from the current * The child view is obtained in the activity's root view, so the nullpointerexception exception is reported at this time * * View Rootview = Findviewbyid (R.layout.activity_splash); * */setcontentview (Rootview); mhandler = new Handler ();//Initialize gradient animation animation animation = Animationutils.loadanimation ( this, r.anim.alpha);//Set Animation listener Animation.setanimationlistener (new Animationlistener () {@Overridepublic void Onanimationstart (Animation Animation) {//TODO auto-generated method stub} @Overridepublic void Onanimationrepeat ( Animation Animation) {//TODO auto-generated method stub} @Overridepublic void Onanimationend (Animation Animation) {// When the monitor hears the end of the animation, it starts to jump to mainactivity mhandler.post (new Runnable () {@Overridepublic void run () {Intent i = new Intent ( Splashactivity.this, Mainactivity.class); startactivity (i); SplashActivity.this.finish ();}); /Start Play animation rootview.startanimation (animation);} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is PR Esent.getmenuinflater (). Inflate (R.menu.splash, menu); return true;}}


I hope the above content is helpful to you.

Android's welcome screen with gradient animations

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.