Android Notes: App application startup interface splashactivity use _android

Source: Internet
Author: User

At present, more mature applications will basically be in the application of the display of a startup interface.
This startup interface is either simple, or complex, or shabby, or gorgeous, with different intentions and different styles.
Here are a few popular applications for the launch interface.

1. Compare
To Tencent QQ, Sina Weibo,uc browser, game Temple escape, such as 7 applications for example, Bibi see:

(I think the most exquisite interface should be qq2012, although only a picture, the basic application name, version, icon of this information are all, but look comfortable, feel beautiful.)

2. Element
The original intention of the interface is to use a friendly user interface to mask the background buffer loading, so that users with a calm waiting mood into the normal application interface.
But since the launch interface is at the beginning, at this particular point, more can be done, such as application promotion, display of copyright, display ads, and so on.
So, the element that starts the interface, can be much less, depends on your intention and demand.
Here's a list of some common elements:
(1). Application Name
(2). Application version
(3). Application icon
(4). Copyright
(5). A sentence description
(6). Progress bar
(7). Additional information, such as Market edition, exclusive starting, etc.
... ...

3. Advantages
Starting the interface with a comprehensive consideration, at least these advantages can be exploited:
(1). Friendly waiting interface, which is the most basic
(2). The basic description of the application, publicity introduction
(3). Dynamic Advertising, Full-screen advertising
(4). Application of the attribute description such as version, copyright and other information, know the user's current application of the basic attributes
From a technical point of view, there are the following:
(5). Loading time-consuming resources
(6). Check the new version
(7). Preset conditions
(8). Code Separation
... ...

4. Layout
Add the elements to add, do a design-free launch interface, the layout is as follows:

Copy Code code as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:orientation= "Vertical"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:background= "#ffffff" >
<textview android:id= "@+id/copy_right"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:padding= "12dip"
Android:layout_centerhorizontal= "true"
Android:layout_alignparentbottom= "true"
Android:text= "by xxxxx produced"
Android:textsize= "11sp"/>
<relativelayout android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent" >
<linearlayout
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:orientation= "Vertical"
Android:layout_centerinparent= "true" >
<relativelayout android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_gravity= "Center_horizontal" >
<imageview android:id= "@+id/jay_studio_icon"
Android:layout_width= "110dip"
android:layout_height= "130dip"
android:src= "@drawable/app_jay"/>
<imageview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_torightof= "@id/jay_studio_icon"
android:src= "@drawable/icon"/>
</RelativeLayout>
<linearlayout android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_gravity= "Center_horizontal" >
<textview android:id= "@+id/app_name"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:padding= "6dip"
android:text= "@string/app_name"
Android:textsize= "24sp"/>
<textview android:id= "@+id/version_name"
Android:layout_width= "Wrap_content"
android:layout_height= "Fill_parent"
android:gravity= "Bottom"
Android:paddingbottom= "6dip"
Android:textsize= "14sp"/>
</LinearLayout>
<view android:layout_width= "Fill_parent"
android:layout_height= "1px"
android:layout_marginleft= "20dip"
android:layout_marginright= "20dip"
android:background= "#dddddd"/>
<textview android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_gravity= "Center_horizontal"
Android:padding= "6dip"
android:text= "@string/setting_about_description"
Android:textsize= "13sp"/>
<progressbar android:id= "@+id/refresh_list_footer_progressbar"
Android:layout_width= "24dip"
android:layout_height= "24dip"
android:indeterminatedrawable= "@anim/app_refresh_progress"
android:layout_gravity= "Center" >
</ProgressBar>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>

This layout only means that the effect is as follows:

5. Code Separation
Specifically to this point to emphasize, is to enhance the writing Program code separation awareness, reduce the mix.
For example, check the new version of this operation,
If placed in the main interface, it is easy to be a separate operation and load data operations mixed together, increasing the complexity of the main interface code,
If you put it in the startup interface, it will appear cleaner and clearer in the boot module (because the new version should be executed when the application starts). You can also consider whether to allow users to enter the main interface (when you decide to completely discard the old version, sometimes you need to force the user to upgrade to the new version).
Some other actions, by so doing, may also be optimized to the code structure.

6. Perform Tasks asynchronously
In the start of the interface friendly display, the background can do a lot of operations, these background operations can use Asynctask to the simplest implementation.
Other methods can be, but I think this time asynctask is the most concise, at this point do not asynctask when to use Asynctask.

Copy Code code as follows:

public class Splashactivity extends Baseactivity {

private static final int failure = 0; Failed
private static final int SUCCESS = 1; Success
private static final int OFFLINE = 2; If you support offline reading, go to offline mode

Private TextView Mversionnametext;

@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.splash);

Mversionnametext = (TextView) Findviewbyid (r.id.version_name);
Mversionnametext.settext (Baseapplication.mversionname);

... ...
New Asynctask<void, Void, integer> () {

@Override
Protected Integer doinbackground (Void ... params) {
int result;
... ...
result = Loadingcache ();
... ...
return result;
}

@Override
protected void OnPostExecute (Integer result) {

};
}.execute (New void[]{});
}

private int Loadingcache () {
if (baseapplication.mnetworkstate = = Networkutils.networn_none) {
return OFFLINE;
}
... ...
return SUCCESS;
}

}

The background of the operation of all put into the Doinbackground method, and finally returned three states, as the result of background execution.

7. Jump Animation
In the OnPostExecute approach, we will eventually have to jump to another activity and finish ourselves off.
This jump animation, in my mobile phone default is left and right slide out of the, in fact, this animation can be customized, such as using the fade in the rotation of the drawing.
First, the two animated fade_in.xml and fade_out.xml that define fade are placed in the Res/anim folder:

Copy Code code as follows:

<!--fade_in.xml-->
<?xml version= "1.0" encoding= "Utf-8"?>
<set xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:shareinterpolator= "false" >
<alpha
Android:fromalpha= "0"
Android:toalpha= "1"
Android:duration= "/>"
</set>

<!--fade_out.xml-->
<?xml version= "1.0" encoding= "Utf-8"?>
<set xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:shareinterpolator= "false" >
<alpha
Android:fromalpha= "1"
Android:toalpha= "0"
Android:duration= "/>"
</set>

Then, call the Overridependingtransition method after finish to use the animation file above:
Copy Code code as follows:

@Override
protected void OnPostExecute (Integer result) {
// ... ...
Intent Intent = new Intent ();
Intent.setclassname (Splashactivity.this, getString (r.string.splash_out_activity));
StartActivity (Intent);
Finish ();
Two parameters representing the entry of the animation, exiting the animation
Overridependingtransition (r.anim.fade_in, r.anim.fade_out);
};

8. Minimum display time
In the actual work, found a small problem, it is possible that the background operation is very short, so that the direct jump, too fast to cause a flash of the feeling, so we need to define a minimum display time, take a value of 800ms.
Copy Code code as follows:

private static final int show_time_min = 800;
// ... ...
{
@Override
Protected Integer doinbackground (Void ... params) {
int result;
Long starttime = System.currenttimemillis ();
result = Loadingcache ();
Long loadingtime = System.currenttimemillis ()-starttime;
if (Loadingtime < show_time_min) {
try {
Thread.Sleep (Show_time_min-loadingtime);
catch (Interruptedexception e) {
E.printstacktrace ();
}
}
return result;
}
}

Such a jump, there will never be a flash feeling, but the 800ms is a very short time, will not cause interference to the user experience.

9. Summary
Starting the interface is a relatively simple topic, for some of the problems encountered, this article made a small collation to make a record.

Related Article

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.