Thursday, 17 May 2018

How to Add Animation when change Activity in Android

- First Make anim Folder in res directory.(/res/anim)

- Make one xml file inside anim folder name is open_next.xml(/res/anim/open_next.xml)

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:interpolator="@android:anim/accelerate_interpolator"
        android:fromXDelta="100%"
        android:toXDelta="0"
        android:duration="300" />
</set>

- Make another xml file inside anim folder name is close_next.xml(/res/anim/close_next.xml)

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:interpolator="@android:anim/accelerate_interpolator"
        android:fromXDelta="0"
        android:toXDelta="100%p"
        android:duration="600" />
</set>

- Add Following code in Main Java class when change Activity

  Intent intent = new Intent(getApplicationContext(), OptionActivity.class);
  startActivity(intent);
  overridePendingTransition(R.anim.open_next, R.anim.close_next);


No comments:

Post a Comment