Some time ago it was someone who asked me how his Android app would be a welcome interface for an ad that would automatically jump to the main interface after a few seconds.
This is the similar effect below. If you want to insert any advertisement, you should change the picture.
Then I think about it, using an animated class of Android animation ... In fact, there is one thing on the Android API development document. I can look it up. Just like the one in the picture below. Also belong to the interface view under a class method ...
Actually this thing, how to say it.
My main words are still a small white to read the understanding of a tutorial class article.
First step.
Let's start by creating a new Anim folder in our project to keep the dynamic effect of some of the countdown text that will be used. (think or cut a screen, afraid some comrades still can not understand ...) No other meaning)
See, that's it. Create a new Anim folder in the folder where your Android project is stored and create a new animation_text.xml
XML file, you'll know what it's for later.
Down here.
In the second step, we start adding content.
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Setxmlns:android= "Http://schemas.android.com/apk/res/android" >3 4 <Alpha5 android:duration= "+"6 Android:fromalpha= "0.0"7 Android:toalpha= "1.0" />8 9 < ScaleTen android:duration= "$" One Android:fromxscale= "1.5" A Android:fromyscale= "1.5" - Android:pivotx= "50%" - Android:pivoty= "50%" the Android:toxscale= "1.0" - Android:toyscale= "1.0" /> - - </Set>
The above effect, if you do not know what these attributes mean, then you can Baidu, I say this one is a bit wordy.
Let's get to the point, what's the use of the above writing? Look at the following, then we have to start to put the interface layout out, and then we will start,
Make a similar interface to me. We use framelayout layout, if know is what layout way, I think should see understand it.
1 <Framelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 Android:background= "@drawable/page24"6 Tools:context= "${relativepackage}.${activityclass}" >7 8 <LinearLayout9 Android:layout_width= "Wrap_content"Ten Android:layout_height= "Wrap_content" One android:layout_gravity= "Right" A android:orientation= "Horizontal" > - - <TextView the Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" - android:layout_gravity= "Right" - Android:text= "Ad countdown:" + Android:textcolor= "#ffffff" - android:textsize= "20SP" /> + A <TextView at Android:id= "@+id/textview" - Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" - android:layout_gravity= "Right" - Android:text= "5" - Android:textcolor= "#ffffff" in android:textsize= "20SP" /> - to <TextView + Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" the android:layout_gravity= "Right" * Android:text= "S" $ Android:textcolor= "#ffffff"Panax Notoginseng android:textsize= "20SP" /> - </LinearLayout> the + </Framelayout>
So here's how we're going to write about how it's implemented inside the app, and that's where our Java program comes in.
In this case, we will write your Java file in the package under the SRC file under the project. Let's take it slow, don't worry.
1 /**2 * 3 * 1. Declaration Interface4 * 2. Define variables5 * 3. Call class animation6 * 4. Write a method to make it move.7 * @authorRain8 *9 */Ten Public classWelcomeactivityextendsactivity{ One A //declaring a Control object - PrivateTextView TextView; - //How much time is declared; the Private intCount = 5; - PrivateAnimation Animation; - - @Override + protected voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); + //The following is the way to remove the title A requestwindowfeature (window.feature_no_title); at Setcontentview (r.layout.activity_welcome); - //initializes the control object TextView -TextView =(TextView) Findviewbyid (R.id.textview); -Animation = Animationutils.loadanimation ( This, r.anim.animation_text); -Handler.sendemptymessagedelayed (0, 1000); - in - } to + //We 're writing a way to get to the main interface after the end of the ad time that calculates the welcome interface . - Private intGetCount () { thecount--; * if(count = = 0) { $Intent Intent =NewIntent ( This, Mainactivity.class);Panax Notoginseng startactivity (intent); - finish (); the } + returncount; A } the + //to handle a message -@SuppressLint ("Handlerleak") $ PrivateHandler Handler =NewHandler () { $ Public voidhandlemessage (android.os.Message msg) { - if(Msg.what = = 0) { -Textview.settext (GetCount () + ""); theHandler.sendemptymessagedelayed (0, 1000); - Animation.reset ();Wuyi textview.startanimation (animation); the } - Wu }; - About }; $ -}
The use of the time to pay attention to the introduction of the package ha.
This will automatically jump to the main interface of the advertising interface is complete.
Thank you for watching. We can speak freely and express our views, and we will accept them humbly.
On the Android Advertising Welcome screen (Countdown)