Android: several common animations about Animation
Add some animation effects to improve user experience. This time we will talk about some common animations ~
Such as transparent animation and gradient animation.
Let's take a look at the run:
VcnPtPrC66Os16LKzdC01Nq0 + large "brush: java;">Package com. vrinux. animotiondemo; import android. app. activity; import android. OS. bundle; import android. view. view; import android. view. animation. alphaAnimation; import android. view. animation. animation; import android. view. animation. animationSet; import android. view. animation. rotateAnimation; import android. view. animation. scaleAnimation; import android. view. animation. translateAnimation; import android. widget. imageView; public class MainActivity extends Activity {private ImageView imgObj; private Animation animation; private AnimationSet animationSet; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); imgObj = (ImageView) findViewById (R. id. imgid);} public void animationshow (View view) {switch (view. getId () {case R. id. btn01id:/*** transparent Animation: AlphaAnimation (float fromAlpha, // Alpha value of the starting state of change; float * toAlpha) // Alpha value of the ending state of change; */animation = new AlphaAnimation (0.0f, 1.0f); // set the animation duration; animation. setDuration (3000); // Add an animation for the component; imgObj. setAnimation (animation); break; case R. id. btn02id:/*** gradient Animation: Ratio of ScaleAnimation (float fromX, // ratio of the X axis (that is, the width) of the Start state to the X axis (that is, the width) of the control, * 1.0f indicates the width of the Control. 0.0f indicates that there is no width, which is a multiple greater than the width of the 1.0f control. float * toX, // Changes the X axis (that is, the width) of the end state) proportion to the X axis (that is, the width) of the control; float fromY, * // ratio of the Start State Y axis (that is, the height) to the Y axis (that is, the height) of the control, which is the same as fromX; float toY, * // ratio of the Y axis (that is, the height) of the control to the Y axis (that is, the height) of the control; float ready Tx, // the X axis coordinate of the changed origin; float * Ready ty) // y axis of the changed origin; */animation = new ScaleAnimation (0.5f, 2.0f, 0.5f, 2.0f, 50366f, 50366f); animation. setDuration (1, 3000); imgObj. setAnimation (animation); break; case R. id. btn03id:/*** displacement Animation: TranslateAnimation (float fromXDelta, // position of the starting X axis of the displacement; float * toXDelta, // position of the ending X axis of the displacement; float fromYDelta, // position of the Start Y axis of the displacement; float * toYDelta) // position of the Y axis of the displacement end; */animation = new TranslateAnimation (0.0f, 1001_f, 0.0f, 1001_f); animation. setDuration (1, 3000); imgObj. setAnimation (animation); break; case R. id. btn04id:/*** rotation Animation: RotateAnimation (float fromDegrees, // start rotation degree; float * toDegrees, // end rotation degree; float rotate Tx, // X axis coordinate of the rotation origin; float * Ty) // y axis coordinate of the rotation origin; */animation = new RotateAnimation (0.0f, 360.0f, 501_f, 501_f); animation. setDuration (1, 3000); imgObj. setAnimation (animation); break; case R. id. btn05id:/*** AnimationSet (true) // an animation set (combination); as the name suggests; */AlphaAnimation animation1 = new AlphaAnimation (0.0f, 1.0f ); scaleAnimation animation2 = new ScaleAnimation (0.5f, 2.0f, 0.5f, 2.0f, 501_f, 501_f); TranslateAnimation animation3 = new branch (0.0f, 1001_f, 0.0f, 1001_f ); rotateAnimation animation4 = new RotateAnimation (0.0f, 360.0f, 50366f, 50366f); animationSet = new AnimationSet (true); animationSet. addAnimation (animation1); animationSet. addAnimation (animation2); animationSet. addAnimation (animation3); animationSet. addAnimation (animation4); animationSet. setDuration (1, 4000); imgObj. setAnimation (animationSet); break ;}}}
Activity_main.xml:
Image resources:
Img.jpg: