Android UI often uses instances how to implement the Welcome Interface (Splash screen)

Source: Internet
Author: User

Under the Android platform. After downloading an app, the first open is splash screen, not to mention the Android design principles do not advocate such splash screen. Let's take a look at the general scenario of using splash screen:

1, after the first installation, a simple app splash screen to achieve the purpose of brand marketing, complex point of the app to provide novice guidance;

2. The version number is updated. Describes the new feature of the version number.

Some people scoff at this design. Some people flock to, the good or bad is not our discussion of the list.

1, Simple splash screen

Such a splash screen implementation and its simplicity. Often used to display product logo or version number and other simple information, we just need to find a way to let Welcomeactivity run a few seconds after their own initiative to jump to the application of the main interface can be;

We just need to use a simple method:

//3s后,运行run方法启动主界面Activity    new Handler().postDelayed(new Runnable() {            @Override            publicvoidrun() {                new Intent(SplashScreen.this, MainActivity.class);                startActivity(i);                //启动主Activity后销毁自身                finish();            }        3000);
2, splash screen involving complex operation

The so-called complex operation is due to the fact that such applications often require very many background operations before entering the interface, allowing the user to wait through splash screen. The operations generally involved are:

    • Get data from the network and store it locally
    • Download image
    • Obtaining and parsing files such as Json/xml
    • Send data to the service side
    • Identity verification
    • 。。。。

It's usually similar to a time-consuming operation like a Web download, but it has to be done before the app enters the main interface. Depending on the application, the work is also different, here we take a remote image as an example, we enter the Welcome interface, we start to download a picture from the remote, after we have entered the main interface, the download good pictures displayed in the main interface;

    1. image address::
    2. To create a splashscreen layout:res/layout/splash_screen.xml
<linearlayout  xmlns: Android  = "http://schemas.android.com/apk/res/android"  xmlns:tools  =" Http://schemas.android.com/tools " android:gravity  = "center"  android:orientation  = "vertical"  android:layout_height  =" match_parent " android:layout_width  =;     <imageview  android:id
      = "@+id/appimage"  android:src  = "@mipmap/logo"  android:layout_width  =" wrap_content " android:layout_height  =" wrap_content "/>     <TextViewandroid:gravity="center"android:text="Welcome to Ms_ Movie "android:layout_margintop=" 15DP "android:textsize=" 30sp "  Android:textcolor="#00ACED"android:layout_width="Wrap_content"  Android:layout_height="wrap_content" />                                                            </linearlayout>

Layout effect

    1. To create a mainactivity layout: to res/layout/activity_main.xml display only images obtained from remote
    <relativelayout xmlns:android="Http://schemas.android.com/apk/res/android" xmlns:tools="Http://schemas.android.com/tools"android:gravity="center" android:layout_width="Match_parent"android:layout_height="Match_parent" >                    <ImageViewandroid:id= "@+id/image"android:layout_width="Wrap_ Content "android:layout_height=" wrap_content " />                            </relativelayout>

4. Over splashscreenactivity, we use Asynctask to run the fetch and parse data, passing the data to mainactivity through intent,

 Public  class splashscreenactivity extends Activity {    Private Static FinalString url="Http://www.jycoder.com/json/Image/1.jpg"; @Overrideprotected voidOnCreate (Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.splash_screen);/ * * Simple splash screen Implementation * */        /* * 3s after running the Run method to start the main interface activity new Handler (). postdelayed (New Runnable () {@Override                    public void Run () {Intent i = new Intent (splashscreen.this, Mainactivity.class);                    StartActivity (i);                Destroy self finish () after initiating main activity;        }}, 3000); * */        //Run tasks in the background, incoming URLs        NewFetchdatatask (). Execute (URL); } Public  class fetchdatatask extends asynctask<String,Void, Bitmap>{        //Pre-run call@Overrideprotected voidOnPreExecute () {Super. OnPreExecute (); }//Run background tasks@OverrideprotectedBitmap Doinbackground (String ... strings) {Bitmap bitmap=NULL;Try{//Through the incoming picture address, get the pictureHttpURLConnection connection= (HttpURLConnection) (NewURL (strings[0]). OpenConnection ();                InputStream Is=connection.getinputstream ();            Bitmap= Bitmapfactory.decodestream (IS); }Catch(IOException e)            {E.printstacktrace (); }returnBitmap }//Call when task is complete@Overrideprotected voidOnPostExecute (Bitmap result) {Super. OnPostExecute (Result);//transmit the obtained data to mainactivity via intentIntent intent=NewIntent (splashscreenactivity. This, Mainactivity.class);//Note that when intent pass a picture, the picture object should not be larger than 40KIntent.putextra ("Image", result); StartActivity (Intent);//Destroy itself after starting mainactivityFinish (); }    }}

5. Finished mainactivity. Here, we need to pay attention to how to accept intent.

  Public  class mainactivity extends Activity {        PrivateImageView ImageView;@Override        protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main);        imageview= (ImageView) Findviewbyid (r.id.image); Intent intent=getintent ();if(intent!=NULL){//Note the way intent objects are passedBitmap Bitmap=intent.getparcelableextra ("Image");        Imageview.setimagebitmap (bitmap); }    }}

6. Remember to add Internet access in Manifest.xml. Set Splashscreenactivity to start activity

<?xml version="1.0" encoding="utf-8"?

><manifest xmlns:android="Http://schemas.android.com/apk/res/android" package ="Com.coder.splashscreen" > <uses-permission android:name="Android.permission.INTERNET"/> <applicationandroid:allowbackup="true"android:icon="@mipmap/ Logo "android:label=" @string/app_name "android:theme=" @style/apptheme " > <activityandroid:name=". Splashscreenactivity "android:label=" @string/app_name " > <intent-filter> <action android:name="Android.intent.action.MAIN" /> <category android:name="Android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=". Mainactivity "/> </Application></manifest>

The first time I made a mistake when I was storing a picture in a remote, I encountered a very interesting question:

Later found that the error is due to use intent transfer pictures, size can not exceed 40K, remember OH

The effect after completion:

Summarize:

The above examples are very easy, but basically splash screen of the idea is nothing more than this. I hope to be of some help to you.

Remember to pay attention to the public platform below ~~~o (∩_∩) O haha ~

Reference information: How to implement Android Splash screen

    • Weibo: @ Ming sang Android Black history
    • E-mail: <[email protected]>
    • Personal homepage: Minsan wins the black history of Android Wang
    • Public Number: Itbird

Android UI often uses instances how to implement the Welcome Interface (Splash screen)

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.