Animation of android (1), animationandroid
Android divides animation modes into: property animation, view animation, and drawable animation.
View animation: displays the starting and ending states of an animation, and allows the view to move in a certain way. This animation can only be used for views.
Frame Animation: displays a group of images with drawable to show the animation changes.
1. tweened animation
Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".AnimationActivity" > <ImageView android:id="@+id/animation_img" android:layout_width="150dp" android:layout_height="150dp" android:layout_centerInParent="true" android:src="@drawable/icon_follower" /> <LinearLayout android:id="@+id/action_items" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="horizontal" > <Button android:id="@+id/btn_alphaanimation" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:text="@string/alpha_animation" /> <Button android:id="@+id/btn_rotateanimation" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:text="@string/rotate_animation" /> <Button android:id="@+id/btn_scaleanimation" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:text="@string/scale_animation" /> <Button android:id="@+id/btn_translationanimation" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:text="@string/scale_animation" /> </LinearLayout></RelativeLayout>
Activity:
Package com. joyfulmath. animatatorsamples; import android. OS. bundle; import android. app. activity; import android. util. log; import android. view. menu; import android. view. view; import android. view. view. onClickListener; import android. view. animation. accelerateDecelerateInterpolator; import android. view. animation. alphaAnimation; import android. view. animation. animation; import android. view. animation. animation. animationListener; import android. view. animation. bounceInterpolator; import android. view. animation. linearInterpolator; import android. view. animation. overshootInterpolator; import android. view. animation. rotateAnimation; import android. view. animation. scaleAnimation; import android. view. animation. translateAnimation; import android. widget. button; import android. widget. imageView; public class AnimationActivity extends Activity implements OnClickListener {private static final String TAG = "updated"; Button mAlphaAnimation = null; Button identifier = null; Button mScaleAnimation = null; Button mTranslationAnimation = null; imageView mImage = null; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_animation_main); mAlphaAnimation = (Button) this. findViewById (R. id. btn_alphaanimation); mAlphaAnimation. setOnClickListener (this); mRotateAnimation = (Button) this. findViewById (R. id. btn_rotateanimation); mRotateAnimation. setOnClickListener (this); mScaleAnimation = (Button) this. findViewById (R. id. btn_scaleanimation); mScaleAnimation. setOnClickListener (this); mTranslationAnimation = (Button) this. findViewById (R. id. btn_translationanimation); mTranslationAnimation. setOnClickListener (this); mImage = (ImageView) this. findViewById (R. id. animation_img);} @ Override public boolean onCreateOptionsMenu (Menu menu) {// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater (). inflate (R. menu. animation, menu); return true;} @ Override public void onClick (View v) {// TODO Auto-generated method stub switch (v. getId () {case R. id. btn_alphaanimation: startAlphaAnimation (); break; case R. id. btn_rotateanimation: startRotateAnimation (); break; case R. id. btn_scaleanimation: startScaleAnimation (); break; case R. id. btn_translationanimation: startThanslationAnimation (); break ;}} private void startRotateAnimation () {Log. I (TAG, "[startRotateAnimation]"); // Animation. RELATIVE_TO_SELF the center of rotate Animation rotateaAni = new RotateAnimation (0f, 360f, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f); rotateaAni. setDuration (3000); rotateaAni. setFillAfter (true); rotateaAni. setInterpolator (new LinearInterpolator (); mImage. startAnimation (rotateaAni);} private void startAlphaAnimation () {Log. I (TAG, "[startAlphaAnimation]"); AlphaAnimation alphaAni = new AlphaAnimation (1.0f, 0.5f); alphaAni. setDuration (3000); alphaAni. setFillAfter (true); alphaAni. setInterpolator (new OvershootInterpolator (); alphaAni. setAnimationListener (new AnimationListener () {@ Override public void onAnimationStart (Animation arg0) {// TODO Auto-generated method stub Log. I (TAG, "[onAnimationStart]") ;}@ Override public void onAnimationRepeat (Animation arg0) {// TODO Auto-generated method stub Log. I (TAG, "[onAnimationRepeat]") ;}@ Override public void onAnimationEnd (Animation arg0) {// TODO Auto-generated method stub Log. I (TAG, "[onAnimationEnd]") ;}}); mImage. startAnimation (alphaAni);} private void startScaleAnimation () {float fromX; // 1.0f to 0.0f float toX; float fromY; float toY; int limit txtype; // where is the last place after scale float limit txvalue; int limit tytype; float limit tyvalue; // Animation. ABSOLUTE, // the last place with X ordinate with absolute diff 20f // Animation. RELATIVE_TO_SELF, // specified dimension to self // Animation. RELATIVE_TO_PARENT. // specified dimension to parent move 100% = 1f with diff (% parent diff) ScaleAnimation scaleAnim = new ScaleAnimation (1.0f, 0.5f, 1.0f, 0.5f //, Animation. ABSOLUTE, 20f, Animation. RELATIVE_TO_PARENT, // 2f); // ScaleAnimation (float fromX, float toX, float fromY, float toY) using Animation. ABSOLUTE, Juan, y = 0; scaleAnim. setDuration (1, 3000); scaleAnim. setFillAfter (true); scaleAnim. setInterpolator (new OvershootInterpolator (); mImage. startAnimation (scaleAnim);} private void startThanslationAnimation () {Log. I (TAG, "[startThanslationAnimation]"); // Animation. ABSOLUTE where is the last point show place // the start x, y ordinate is the current place with TranslateAnimation anmit = new TranslateAnimation (Animation. RELATIVE_TO_PARENT, 0.1f, Animation. RELATIVE_TO_PARENT, 0.5f, Animation. RELATIVE_TO_PARENT, 0.2f, Animation. RELATIVE_TO_PARENT, 0.6f); anmit. setDuration (1, 3000); anmit. setFillAfter (true); anmit. setInterpolator (new BounceInterpolator (); mImage. startAnimation (anmit );}}
Animation is a conversion animation, that is, the actual response position and size are not changed, but only the transformation on The View.
This kind of animation is cost-effective and efficient.
These classes are inherited from android. view. animation. Animation
2. animationset
A view animation combination only uses multiple State Transformations of a view object.
/** * Constructor to use when building an AnimationSet from code * * @param shareInterpolator Pass true if all of the animations in this set * should use the interpolator associated with this AnimationSet. * Pass false if each animation should use its own interpolator. */ public AnimationSet(boolean shareInterpolator) { setFlag(PROPERTY_SHARE_INTERPOLATOR_MASK, shareInterpolator); init(); }
As shown in the androidsdk source code, shareInterpolator will decide to use the interpolator of each animation
Or the transformation method of the animationset.
The transformation of the animationset can only be played together. Only the startoffset method can be used to simulate the sequence of changes.
3. android. view. animation. BaseInterpolator
Conversion Method:
What is supported before the end is:
AccelerateDecelerateInterpolator, slow start and end transformations, fast intermediate Transformations
AccelerateInterpolator, starts to slow, and then accelerates
AnticipateInterpolator, the conversion will have a callback, that is, the first backward transformation, and then the transformation according to the given key frame.
AnticipateOvershootInterpolator, An interpolator where the change starts backward then flings forward and overshoots the target value and finally goes back to the final value
BounceInterpolator, Bayesian Curve
CycleInterpolator, sin Curve
DecelerateInterpolator, slowing down and changing
LinearInterpolator, default, linear transformation
OvershootInterpolator, An interpolator where the change flings forward and overshoots the last value then comes back.
PathInterpolator 5.1 new features. You can customize the path conversion method.