Android provide series of simple transformations (position, size, rotation, and so on) to the content of a View. This transformation or animation is handled by the package android.view.animation.
In this blog, we will be animating a view by application rotation and translate transformation over a view.
RotationAnimation
An animation that controls the rotation of an object. This rotation takes place in the X-Y plane. You can specify the point to use for the center of the rotation, where (0,0) is the top left point. If not specified, (0,0) is the default rotation point.
1 2 3 4 5 |
RotateAnimation rotate = new RotateAnimation(fromDegrees, toDegrees, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotate.setDuration(500); rotate.setInterpolator(new LinearInterpolator()); rotate.setFillAfter(true); imageView.startAnimation(rotate); |
TranslateAnimation
An animation that controls the position of an object.
1 2 3 4 5 6 |
Animation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 5.2f, Animation.RELATIVE_TO_SELF, 0.0f); translateAnimation.setDuration(400); translateAnimation.setFillEnabled(true); imageView.startAnimation(translateAnimation); |