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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 339
    Comment on it

    In the below example I have created a animation button. Here I have added Button and TextView in activity_main xml layout then I have created new directory (anim) , In anim directory I have created new anim_traslate.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 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"
            android:textAlignment="center"
            android:layout_marginTop="20dp"
            android:textSize="20dp"
            android:textColor="@color/colorAccent"/>
    
        <Button
            android:id="@+id/click"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_marginTop="20dp"
            android:text="Click" />
        </LinearLayout>
    
    Step(2)MainActivity-
    public class MainActivity extends AppCompatActivity {
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            final Animation animTranslate = AnimationUtils.loadAnimation(this, R.anim.anim_translate);
    
    
            Button btnTranslate = (Button)findViewById(R.id.click);
    
            btnTranslate.setOnClickListener(new Button.OnClickListener(){
    
                @Override
                public void onClick(View arg0) {
                    arg0.startAnimation(animTranslate);
                }});
    
    
        }
    }
    Step(3)-Create new directory anim and created here new anim_traslate1.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">
        <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: