Recently looking at the Jammendo code, the learning process is intended to be a simple record, the following begins the first article:
After opening the Jammendo run, pop up a dialog box, after skipping the dialog box, there will be a fade-out interface to the implementation of the first page effect. So the effect is how to achieve, in fact, animation animation fade out of the effect-the principle is probably the layout of opaque into full transparency such a principle.
I use the custom endanimation here, is the animation effect of execution, here to find my pre-written fade_out.xml, that is, a simple fade effect implementation:
<? xml version= "1.0" encoding= "Utf-8" ?> < set xmlns:android = "Http://schemas.android.com/apk/res/android" > < alpha android:fromalpha = "1.0" Android:toalpha = "0.0" Android:duration = " /> </ set >
Fromalpha for animation start transparency, Toalpha is the animation end transparency, duration as the name implies animation duration, of course, there will fade out also fade in, write the principle of almost, the relevant code on the Internet, you can find it yourself, very simple.
OK, after reading the above animated XML file: Let's start by looking at how the code should be written in the activity
Here, I use handler and runnable to achieve a simple animation fade-out effect, Android animation effect is based on the animation to achieve, the simple implementation of the fade effect implementation
1 Public classSplashscreenactivityextendsActivity {2 PrivateAnimation endanimation;3 PrivateHandler Endanimationhandler;4 PrivateRunnable endanimationrunnable;5 @Override6 protected voidonCreate (Bundle savedinstancestate) {7 //TODO auto-generated Method Stub8 Super. OnCreate (savedinstancestate);9 Setcontentview (r.layout.splashlayout); TenEndanimation = Animationutils.loadanimation ( This, r.anim.fade_out); OneEndanimation.setfillafter (true); A -Endanimationhandler =NewHandler (); -Endanimationrunnable =NewRunnable () { the @Override - Public voidrun () { - Findviewbyid (r.id.splashlayout). Startanimation (endanimation); - } + }; - +Endanimation.setanimationlistener (NewAnimationlistener () { A @Override at Public voidOnanimationstart (Animation Animation) {} - - @Override - Public voidonanimationrepeat (Animation Animation) {} - - @Override in Public voidonanimationend (Animation Animation) { - //Homeactivity.launch (splashscreenactivity.this); to //SplashscreenActivity.this.finish (); + } - }); the * endanimationhandler.removecallbacks (endanimationrunnable); $Endanimationhandler.postdelayed (Endanimationrunnable, 2000);Panax Notoginseng } - the}
splashscreenactivityFirst I defined a endanimation,endanimation is the execution of the animation effect, here to find my pre-written fade_out.xml, that is, a simple fade effect implementation, It then uses the animationutils.loadanimation to load the animated effect. Here is a setfillafter (true) function, I searched the information, presumably explained that: the Setfillafter () method is used to set an animation after the execution, the view object remains in the position of the middle finger, if set to false, to indicate that enable, That is, it does not stop at the terminating position, where we set to false. After the definition of a endanimationhadler and a endanimationrunnable, is the specific call this animation thread, handler processing multithreading usually with runnable interface, about this I also do not understand, not much mention.
New Handler ();
New Runnable () {
Public void run () { Findviewbyid (r.id.splashlayout). Startanimation (endanimation); } };
The specific animation effect call will be implemented in the Endanimationrunnable run () method, and you can see that in the Run method, I used Findviewbyid to find a splashlayout, This splashlayout is the ID of the layout resource in the current activity layout, not the ID of the entire xxx.xml file. In the previous process, a long time to find that the project could not be run, and later found that I have been using r.layout.splashlayout. It is important to note that we are not adding an XML layout, but rather the ID of the layout resource in the Xxx.xml file. As shown below:
<LinearLayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:id= "@+id/splashlayout"xmlns:android= "Http://schemas.android.com/apk/res/android"> <TextViewAndroid:id= "@+id/splashtextview"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:text= "@string/hello_world" ></TextView></LinearLayout>
The next step is to implement some Onanimationstart,onanimationrepeat,onanimationend callback methods for Endanimation, in the Onanimationend method, that is, after the animation effect is finished, We can perform some custom events, such as page jumps and so on. Once the above process is complete, you can call Hadler to perform the animation fade-out effect we completed with the following code:
endanimationhandler.removecallbacks (endanimationrunnable); 2000);
OK, above is a simple fade effect implementation, written on April 6
Learning the mental process of Jammendo code (i) Simple fade-out effect implementation