Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create rotate animation buttun in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 300
    Comment on it

     In the below example I have created rotate animation button. In below code I have used scale and translate effect on rotate animation button. Here I have added Button in button i have used an img and added a TextView in activity_main xml layout then I have created new directory (anim) , In anim directory I have created new anim_rotate.xml layout. In MainActivity I have used AnimationUtils.loadAnimation function and setOnClickListener method. You can see below program it will clearly describe you how to create rotate animation  button in android.

    Step(1)activity_main.xml layout-

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Animation Button with Image"
            android:textAlignment="center"
            android:layout_marginTop="20dp"
            android:textSize="20dp"
            android:textColor="@color/colorAccent"/>
    
    
        <Button
    
            android:drawableLeft="@drawable/wordpress"
            android:id="@+id/click"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:text="Rotate" />
    
    </LinearLayout>

    Step(2)MainActivity-

    public class MainActivity extends AppCompatActivity {
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
    
            final Animation animRotate = AnimationUtils.loadAnimation(this, R.anim.anim_rotate);
            Button btnRotate = (Button)findViewById(R.id.click);
            btnRotate.setOnClickListener(new Button.OnClickListener(){
    
                @Override
                public void onClick(View arg0) {
                    arg0.startAnimation(animRotate);
                }});
        }
    }

    Step(3)-Create new directory anim and created here new rotate_alpha.xml layout-

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/linear_interpolator">
        <rotate
            android:fromDegrees="0"
            android:toDegrees="360"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="500"
            android:startOffset="0"
            android:repeatCount="1"
            android:repeatMode="reverse" />
        <scale
            android:fromXScale="1.0"
            android:toXScale="3.0"
            android:fromYScale="1.0"
            android:toYScale="3.0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="500"
            android:repeatCount="1"
            android:repeatMode="reverse" />
        <translate
            android:fromXDelta="0"
            android:toXDelta="100%p"
            android:duration="500"
            android:repeatCount="1"
            android:repeatMode="reverse"/>
    </set>

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: