{"id":2499,"date":"2017-05-03T08:47:16","date_gmt":"2017-05-03T08:47:16","guid":{"rendered":"http:\/\/webartdevelopers.com\/?p=2499"},"modified":"2017-05-03T09:59:34","modified_gmt":"2017-05-03T09:59:34","slug":"how-to-perform-tween-animationrotate-in-android","status":"publish","type":"post","link":"https:\/\/webartdevelopers.com\/blog\/how-to-perform-tween-animationrotate-in-android\/","title":{"rendered":"How to Perform Tween Animation(Rotate) in Android"},"content":{"rendered":"<p>In this tutorial how to perform Rotation in Tween Animation in Android is shown.<\/p>\n<p>Points to Remember:<\/p>\n<ul>\n<li>For creating the rotation.xml file you will have to first create anim folder under res folder.<\/li>\n<li>At the time of creating rotation.xml file you can either select &#8216;rotate&#8217; or &#8216;set&#8217; as Root Element.<\/li>\n<li>You can also perform clockwise and anticlockwise rotation separately, for that you will have to create another file in anim folder, and don&#8217;t write the &#8216;android:startOffset&#8217; property in this file else it will start the anticlockwise rotation after some delay.<\/li>\n<\/ul>\n<p>Code:<\/p>\n<p>activity_main.xml<\/p>\n<p>&lt;RelativeLayout xmlns:android=&#8221;http:\/\/schemas.android.com\/apk\/res\/android&#8221;<br \/>\nxmlns:tools=&#8221;http:\/\/schemas.android.com\/tools&#8221;<br \/>\nandroid:layout_width=&#8221;match_parent&#8221;<br \/>\nandroid:layout_height=&#8221;match_parent&#8221;<br \/>\nandroid:paddingBottom=&#8221;@dimen\/activity_vertical_margin&#8221;<br \/>\nandroid:paddingLeft=&#8221;@dimen\/activity_horizontal_margin&#8221;<br \/>\nandroid:paddingRight=&#8221;@dimen\/activity_horizontal_margin&#8221;<br \/>\nandroid:paddingTop=&#8221;@dimen\/activity_vertical_margin&#8221;<br \/>\ntools:context=&#8221;.MainActivity&#8221; &gt;<\/p>\n<p>&lt;ImageView<br \/>\nandroid:id=&#8221;@+id\/imageView1&#8243;<br \/>\nandroid:layout_width=&#8221;wrap_content&#8221;<br \/>\nandroid:layout_height=&#8221;wrap_content&#8221;<br \/>\nandroid:layout_alignParentTop=&#8221;true&#8221;<br \/>\nandroid:layout_centerHorizontal=&#8221;true&#8221;<br \/>\nandroid:layout_marginTop=&#8221;129dp&#8221;<br \/>\nandroid:src=&#8221;@drawable\/tweenanm&#8221; \/&gt;<\/p>\n<p>&lt;Button<br \/>\nandroid:id=&#8221;@+id\/b1&#8243;<br \/>\nandroid:layout_width=&#8221;wrap_content&#8221;<br \/>\nandroid:layout_height=&#8221;wrap_content&#8221;<br \/>\nandroid:layout_alignParentBottom=&#8221;true&#8221;<br \/>\nandroid:layout_centerHorizontal=&#8221;true&#8221;<br \/>\nandroid:layout_marginBottom=&#8221;60dp&#8221;<br \/>\nandroid:onClick=&#8221;onRotate&#8221;<br \/>\nandroid:text=&#8221;Rotate&#8221; \/&gt;<\/p>\n<p>&lt;\/RelativeLayout&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>res\/anim\/rotation.xml<\/p>\n<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;<br \/>\n&lt;set xmlns:android=&#8221;http:\/\/schemas.android.com\/apk\/res\/android&#8221;&gt;<br \/>\n&lt;rotate<br \/>\nandroid:fromDegrees=&#8221;0&#8243;<br \/>\nandroid:toDegrees=&#8221;360&#8243;<br \/>\nandroid:pivotX=&#8221;50%&#8221;<br \/>\nandroid:pivotY=&#8221;50%&#8221;<br \/>\nandroid:duration=&#8221;5000&#8243;&gt;&lt;\/rotate&gt;<\/p>\n<p>&lt;rotate<br \/>\nandroid:fromDegrees=&#8221;360&#8243;<br \/>\nandroid:toDegrees=&#8221;0&#8243;<br \/>\nandroid:pivotX=&#8221;50%&#8221;<br \/>\nandroid:pivotY=&#8221;50%&#8221;<br \/>\nandroid:startOffset=&#8221;5000&#8243;<br \/>\nandroid:duration=&#8221;5000&#8243;&gt;&lt;\/rotate&gt;<\/p>\n<p>&lt;\/set&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>MainActivity.java<\/p>\n<p>package com.example.demo;<\/p>\n<p>import android.os.Bundle;<br \/>\nimport android.app.Activity;<br \/>\nimport android.view.Menu;<br \/>\nimport android.view.View;<br \/>\nimport android.view.animation.Animation;<br \/>\nimport android.view.animation.AnimationUtils;<br \/>\nimport android.widget.ImageView;<\/p>\n<p>public class MainActivity extends Activity{<\/p>\n<p>ImageView iv;<\/p>\n<p>@Override<br \/>\nprotected void onCreate(Bundle savedInstanceState) {<br \/>\nsuper.onCreate(savedInstanceState);<br \/>\nsetContentView(R.layout.activity_main);<br \/>\niv=(ImageView)findViewById(R.id.imageView1);<br \/>\n}<\/p>\n<p>public void onRotate(View v)<br \/>\n{<br \/>\nAnimation animation=AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotation);<br \/>\niv.startAnimation(animation);<br \/>\n}<\/p>\n<p>@Override<br \/>\npublic boolean onCreateOptionsMenu(Menu menu) {<br \/>\n\/\/Inflate the menu; this adds items to the action bar if it is present.<br \/>\ngetMenuInflater().inflate(R.menu.main, menu);<br \/>\nreturn true;<br \/>\n}<br \/>\n}<\/p>\n<p><a href=\"https:\/\/youtu.be\/B4gm3h21qdE\">https:\/\/youtu.be\/B4gm3h21qdE<\/a><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"In this tutorial how to perform Rotation in Tween Animation in Android is shown. Points to Remember: For creating the rotation.xml file you will have to first create anim folder under res folder. At the time of creating rotation.xml file you can either select &#8216;rotate&#8217; or &#8216;set&#8217; as Root Element. You can also perform clockwise and anticlockwise rotation separately, for that you will have to create another file in anim folder, and don&#8217;t write the &#8216;android:startOffset&#8217; property in this file else it will start the anticlockwise rotation after some delay. Code: activity_main.xml &lt;RelativeLayout xmlns:android=&#8221;http:\/\/schemas.android.com\/apk\/res\/android&#8221; xmlns:tools=&#8221;http:\/\/schemas.android.com\/tools&#8221; android:layout_width=&#8221;match_parent&#8221; android:layout_height=&#8221;match_parent&#8221; android:paddingBottom=&#8221;@dimen\/activity_vertical_margin&#8221; android:paddingLeft=&#8221;@dimen\/activity_horizontal_margin&#8221; android:paddingRight=&#8221;@dimen\/activity_horizontal_margin&#8221; android:paddingTop=&#8221;@dimen\/activity_vertical_margin&#8221; tools:context=&#8221;.MainActivity&#8221; &gt; &lt;ImageView android:id=&#8221;@+id\/imageView1&#8243; android:layout_width=&#8221;wrap_content&#8221; android:layout_height=&#8221;wrap_content&#8221; android:layout_alignParentTop=&#8221;true&#8221; android:layout_centerHorizontal=&#8221;true&#8221; android:layout_marginTop=&#8221;129dp&#8221; android:src=&#8221;@drawable\/tweenanm&#8221; \/&gt; &lt;Button android:id=&#8221;@+id\/b1&#8243; android:layout_width=&#8221;wrap_content&#8221; android:layout_height=&#8221;wrap_content&#8221; android:layout_alignParentBottom=&#8221;true&#8221; android:layout_centerHorizontal=&#8221;true&#8221; android:layout_marginBottom=&#8221;60dp&#8221; android:onClick=&#8221;onRotate&#8221; <!-- AddThis Advanced Settings generic via filter on get_the_excerpt -->","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62],"tags":[96,97],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2499"}],"collection":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/comments?post=2499"}],"version-history":[{"count":3,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2499\/revisions"}],"predecessor-version":[{"id":2503,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2499\/revisions\/2503"}],"wp:attachment":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/media?parent=2499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/categories?post=2499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/tags?post=2499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}