How to write XML files in rotate
< Rotate android:fromdegrees = "0" android:todegrees= "+350" android:pivotx= "50%" Android:pivoty= "50%" android:duration= "$"/>
*android:todegrees= "+350" positive sign is the direction of rotation, plus is clockwise, minus is counterclockwise
There are three ways to set the value of *android:pivotx
1.android:pivotx= "50" This method uses absolute position positioning (50 of this point on the screen position coordinates)
2.android:pivotx= "50%" This method uses the relative positioning of the control itself
3.android:pivotx= "50%p" This method is positioned relative to the control's parent control
Several other animations are written similar to this
Mainactivity.java
Public classMainactivityextendsActivity {PrivateImageView ImageView; PrivateButton button_1; PrivateButton button_2; PrivateButton button_3; PrivateButton Button_4; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.main); ImageView=(ImageView) Findviewbyid (R.id.imageview); Button_1=(Button) Findviewbyid (r.id.button_1); Button_2=(Button) Findviewbyid (r.id.button_2); Button_3=(Button) Findviewbyid (r.id.button_3); Button_4=(Button) Findviewbyid (r.id.button_4); Alphabuttonlistener Alphabuttonlistener=NewAlphabuttonlistener (); Rotatebuttonlistener Rotatebuttonlistener=NewRotatebuttonlistener (); Scalebuttonlistener Scalebuttonlistener=NewScalebuttonlistener (); Translatebuttonlistener Translatebuttonlistener=NewTranslatebuttonlistener (); Button_1.setonclicklistener (Alphabuttonlistener); Button_2.setonclicklistener (Rotatebuttonlistener); Button_3.setonclicklistener (Scalebuttonlistener); Button_4.setonclicklistener (Translatebuttonlistener); } //fade in and fade Private classAlphabuttonlistenerImplementsOnclicklistener {@Override Public voidOnClick (View v) {//loading an animation file using AnimationutilsAnimation Animation = animationutils.loadanimation (mainactivity. This, R.anim.alpha); Imageview.startanimation (animation); } } //Rotate Private classRotatebuttonlistenerImplementsOnclicklistener {@Override Public voidOnClick (View v) {Animation Animation= Animationutils.loadanimation (mainactivity. This, r.anim.rotate); Imageview.startanimation (animation); } } //level Private classTranslatebuttonlistenerImplementsOnclicklistener {@Override Public voidOnClick (View v) {Animation Animation= Animationutils.loadanimation (mainactivity. This, r.anim.translate); Imageview.startanimation (animation); } } //Zoom Private classScalebuttonlistenerImplementsOnclicklistener {@Override Public voidOnClick (View v) {Animation Animation= Animationutils.loadanimation (mainactivity. This, R.anim.scale); Imageview.startanimation (animation); } }}
Create a new Anim folder under the Res directory
Alpha.xml
<?XML version= "1.0" encoding= "Utf-8"?><Setxmlns:android= "Http://schemas.android.com/apk/res/android"Android:interpolator= "@android: Anim/accelerate_interpolator"> <AlphaAndroid:fromalpha= "1.0"Android:toalpha= "0.0"Android:startoffset= "$"android:duration= "$"/></Set>
Rotate.xml
<?XML version= "1.0" encoding= "Utf-8"?><Setxmlns:android= "Http://schemas.android.com/apk/res/android"Android:interpolator= "@android: Anim/accelerate_interpolator"> <Rotateandroid:fromdegrees= "0"android:todegrees= " the"Android:pivotx= "50%"Android:pivoty= "50%"android:duration= " the"/></Set>
Scale.xml
<?XML version= "1.0" encoding= "Utf-8"?><Setxmlns:android= "Http://schemas.android.com/apk/res/android"> < ScaleAndroid:fromxscale= "1.0"Android:toxscale= "0.0"Android:fromyscale= "1.0"Android:toyscale= "0.0"Android:pivotx= "50%"Android:pivoty= "50%"android:duration= "+"/></Set>
Translate.xml
<?XML version= "1.0" encoding= "Utf-8"?><Setxmlns:android= "Http://schemas.android.com/apk/res/android"Android:interpolator= "@android: Anim/accelerate_interpolator"> <TranslateAndroid:fromxdelta= "50%"Android:toxdelta= "100%"Android:fromydelta= "50%"Android:toydelta= "100%"android:duration= "+"/></Set>
Android animation animations with XML files