On an article about the Android left and right sliding switching, the implementation process is very simple, some novice may be to understand the principle of activity switching, the following mainly on the left and the next slide in-depth discussion, and a project in a transition effect to further understand.
Activitythe toggle effect is using theAndroidthe animated effect,Androidthe animation in the official have relevant information:http://developer.android.com/guide/topics/graphics/animation.htmland thehttp://developer.android.com/guide/topics/resources/animation-resource.html,ActivityThe Toggle animation is actuallyAndroidof theView Animation (View Animations)in theTween Animationeffect,Tween Animationdivided into4animation effects, respectively:Alpha (Transparent Change) Translate (Position Move) Scale (Zoom) Rotate (Rotate), and the left and right slide switch uses theTranslate (Position Move)effect, we'll discuss it in the next article.Alpha (Transparent Change) ,Scale (Zoom),Rotate (Rotate) These three effects, this article will onlyTranslate (Position Move).
Translate animation is a very good understanding, that is, define a starting position and an end position, define the move time, and then can automatically generate mobile animation. Android translate moving direction has landscape (X) Vertical (y), sliding left and right using the lateral movement effect, for vertical (y) position as follows:
defines an upward exiting animation (from the position 2 Move Position 3 ) and enter from below (from position 1 Move Position 2 The animation definition file is as follows:
Out_to_up.xml ( exit from top of screen )
<? XML version="1.0" encoding="utf-8"?> < Translate xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android: Anim/accelerate_interpolator" android:fromydelta="0%p" android:toydelta=" -100%p" android:duration="$"> </ Translate > |
in_from_down.xml ( Enter from below the screen )
<? XML version="1.0" encoding="utf-8"?> < Translate xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android: Anim/accelerate_interpolator" android:fromydelta="100%p" android:toydelta="0%p" android:duration="$"> </ Translate > |
now , let's talk about Translate a few important attributes:
Android:interpolator: accelerators, very useful properties, can be simply understood as the speed of the animation, can be more and more quickly, or it can be more and more slowly, or is fast after the busy, or even the speed, and so on, for the values as follows:
@android: Anim/accelerate_interpolator : getting faster @android: Anim/decelerate_interpolator : More and more slowly @android: Anim/accelerate_decelerate_interpolator : Fast and Slow first @android: anim/anticipate_interpolator: One small step, and then it's speeding forward . @android: Anim/overshoot_interpolator : Quickly reaches the end of a small step and then goes back to the end @android: Anim/anticipate_overshoot_interpolator : Reach the end of a small step and return to the end @android: Anim/bounce_interpolator : To reach the end to produce a pinball effect, bounce back to the end @android: Anim/linear_interpolator : Uniform speed. |
android:duration: animation run time, defined in multiple times ( Ms ) to complete the animation within
Android:startoffset: Run animations after a certain amount of delay
Fromxdelta: X the starting position of the axis direction, can be % , or it can be a specific pixel See figure in detail
Toxdelta: End position of X - axis, either %or specific pixel
Fromydelta: Y the starting position of the axis direction, can be % , or it can be a specific pixel
Toydelta: Y the end position of the axis direction, which can be % , or it can be a specific pixel
Once you understand the above attributes, you can combine a lot of interesting position movement effects. For example, using an accelerator:@android: The Anim/bounce_interpolator can produce the effect of a bouncing ball when it lands.
The actual project needs to use only "left and right swipe" effect may not be good enough, you want to switch to produce more dynamic effect, such as the first switch when the 1 a Activity step back and exit the screen in the left direction. The first 2 Activity is then followed by the right-hand entry screen, which has a dynamic effect when it reaches the end point. After understanding the animation accelerator, we all know that can be used:anticipate_overshoot_interpolator,anticipate_interpolator ,overshoot_interpolator These three accelerators realize the dynamic effect of starting or ending when the left and right slide switch.
The animation file is defined as follows:
Dync_out_to_left.xml
<? XML version = "1.0" encoding = "Utf-8" < translate xmlns:android = "Http://schemas.android.com/apk/res/android" android:duration = "$" android: Fromxdelta = "0%p" android:interpolator = "@android: Anim/anticipate_interpolator" android:toxdelta = " -100%p" /> |
dync_in_from_right.xml
<? XML version = "1.0" encoding = "Utf-8" < translate xmlns:android = "Http://schemas.android.com/apk/res/android" android:duration = "$" android: Fromxdelta = "100%p" android:interpolator = @android: anim/anticipate_overshoot_ Interpolator " Android:toxdelta = "0%p" /> |
However, with the above animation configuration, the following issues occur:
1. Section 1 a Activity Use Anticipate_interpolator , step back and move forward when you start moving. But to step back is too big, slightly exaggerated, the actual application only hope to step back a little steps on the line.
2. due to the beginning of the step backward, the additional move time, resulting in the previous Activity and the latter one Activity time is out of sync.
to solve the above problem, redefine the dynamic effect and 1 a Activity The movement is divided into 2 animation effect: ( 1 ) with $ The millisecond time moves backwards first 2%p the location (2) move forward from 2%p position to -100%p after a delay of up to milliseconds Position. then the first 2 Activity from the delay of Milliseconds and then moves from the 102%p position to the 0%p position.
The animation is defined as follows:
New_dync_out_to_left.xml
<? XML version="1.0" encoding="utf-8"?> < Set xmlns:android="http://schemas.android.com/apk/res/android" android:shareinterpolator="false" > <Translate android:duration="$" android:fromxdelta="0%p" android:interpolator="@android: Anim/accelerate_decelerate_interpolator" android:toxdelta="2%p" /> <Translate android:duration="+" android:fromxdelta="2%p" android:interpolator="@android: Anim/accelerate_interpolator" android:startoffset="$" android:toxdelta=" -100%p" /> </ Set > |
New_dync_in_from_right.xml
<? XML version="1.0" encoding="utf-8"?> < Translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="+" android:fromxdelta="102%p" android:interpolator="@android: Anim/anticipate_overshoot_interpolator" android:startoffset="$" android:toxdelta="0%p" /> |
Package code: http://www.oschina.net/code/snippet_97118_7734
Http://www.cnblogs.com/bavariama/archive/2013/01/29/2881225.html