Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make Custom Animation switching Activity

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 160
    Comment on it

    In the below example I have created Custom Animation while Switching Activity. Here I have created two activity, In first activity I have added left and right xml using methodTransition() and in Second activity I have added top and bottom xml. All these xml (right,left,top,bottom) are created in anim folder. In main.xml and main2.xml I have added button for switching activity. You can see below example code it will clearly describe you how to make Custom Animation switching Activity.

    Step(1)MainActivity-

    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            Button switchButton = (Button)findViewById(R.id.switchbutton);
            switchButton.setOnClickListener(new View.OnClickListener(){
    
                @Override
                public void onClick(View arg0) {
                    Intent intent = new Intent();
                    intent.setClass(MainActivity.this, Main2Activity.class);
                    startActivity(intent);
                    overridePendingTransition(R.anim.right_in, R.anim.left_out);
                }});
        }
    
    }
    
    Step(2)activity_main.xml
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:orientation="vertical"
        tools:context=".MainActivity" >
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Evon"
            android:textSize="25dp"
            android:textColor="#FF4081"
            android:textAlignment="center" />
        <Button
            android:layout_gravity="center"
            android:id="@+id/switchbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Click" />
    
    
    </LinearLayout>
    
    Step(3)Main2Activity-
    public class Main2Activity extends AppCompatActivity {
        @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main2);
    
                Button backButton = (Button) findViewById(R.id.backbutton);
                backButton.setOnClickListener(new View.OnClickListener() {
    
                    @Override
                    public void onClick(View v) {
                        finish();
                        overridePendingTransition(R.anim.bottom_in, R.anim.top_out);
                    }
                });
            }
    
        }
    
    Step(4)activity_main2.xml
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
    
        tools:context=".Activity2" >
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Dehradun"
            android:textSize="25dp"
            android:textColor="#FF4081"
            android:textAlignment="center" />
    
        <Button
            android:layout_marginTop="60dp"
            android:textAlignment="center"
            android:id="@+id/backbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Back" />
    
    </RelativeLayout>
    Step(5)Cretead bottom.xml layout in (anim folder)
    <?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:fromYDelta="100%p"
            android:toYDelta="0"
            android:duration="500"/>
    
    </set>
    Step(6)Cretead top.xml layout in (anim folder)
    <?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:fromYDelta="0"
            android:toYDelta="-100%p"
            android:duration="500"/>
    
    </set>
    
    Step(7)Cretead left.xml layout in (anim folder)
    
    <?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:fromYDelta="0"
                android:toYDelta="-100%p"
                android:duration="500"/>
    
    </set>
    
    
    Step(9)Cretead right.xml layout in (anim folder)
    <?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="100%p"
                android:toXDelta="0"
                android:duration="500"/>
    
    </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: