How to achieve right to left animation to start the activity

android activity transition animation library
open activity with animation android
android activity transition fade
android imageview animation (left to right)
android textview animation (left to right)
android animation (left to right programmatically)
intent animation android
shared element transition - android

I am working on one demo application where I want to apply animation whenever app start any activity. I wrote below code but this is for to animate the activity from left to right.

left_to_right.xml

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <translate android:fromXDelta="-100%" android:toXDelta="0%"
        android:fromYDelta="0%" android:toYDelta="0%"
        android:duration="500"/>
</set>

right_to_left.xml

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <translate
        android:duration="500"
        android:fromXDelta="0%"
        android:fromYDelta="0%"
        android:toXDelta="100%"
        android:toYDelta="0%" />
</set>

I am here starting an activity like this

startActivity(new Intent(this, LoginActivity.class));
overridePendingTransition(R.anim.left_to_right, R.anim.right_to_left);

I want to achieve an animation right to left. How this can be done.

Thanks in advance.

Do these modifications to your animation files:

enter.xml:

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <translate
        android:duration="500"
        android:fromXDelta="100%"
        android:fromYDelta="0%"
        android:toXDelta="0%"
        android:toYDelta="0%" />
</set>

exit.xml:

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <translate
        android:duration="500"
        android:fromXDelta="0%"
        android:fromYDelta="0%"
        android:toXDelta="-100%"
        android:toYDelta="0%" />
</set>

You'll have your second activity sliding in from right to the left.

For a better understanding on how to play around with the fromXDelta and toXDelta values for the animations, here is a very basic illustration on the values:

This way you can easily understand why you add android:fromXDelta="0%" and android:toXDelta="-100%" for your current activity. And this is because you want it to go from 0% to the -100% position.

[EDIT]

So if you want to open ActivityB from ActivityA you do the following(let's say you have a button):

button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(ActivityA.this, ActivityB.class));
            overridePendingTransition(R.anim.enter, R.anim.exit);
        }
    });

Now, if you want to have the "backwards" animation of the first one, when you leave Activity B, you'll need 2 new animation files and some code in the ActivityB's onBackPressed method, like this:

First the animation files: left_to_right.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <translate
        android:duration="500"
        android:fromXDelta="-100%"
        android:fromYDelta="0%"
        android:toXDelta="0%"
        android:toYDelta="0%" />
</set>

right_to_left.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <translate
        android:duration="500"
        android:fromXDelta="0%"
        android:fromYDelta="0%"
        android:toXDelta="100%"
        android:toYDelta="0%" />
</set>

And in ActivityB do the following:

@Override
public void onBackPressed() {
    super.onBackPressed();
    overridePendingTransition(R.anim.left_to_right, R.anim.right_to_left);
}

Also if you have up navigation enabled, you'll have to add the animation in this case as well:

You enable UP navigation like this:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActionBar().setDisplayHomeAsUpEnabled(true);
}

And this is how you handle the animation in this case too:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    // Respond to the action bar's Up/Home button
    case android.R.id.home:
       //NavUtils.navigateUpFromSameTask(this);
       finish();
       overridePendingTransition(R.anim.left_to_right, R.anim.right_to_left);
       return true;
    }
    return super.onOptionsItemSelected(item);
}

Also be aware that even if your code is okay, your phone might have animation turned off. To turn then on do the following:

  1. Open Settings and go to Developer Options
  2. Make sure it is enabled (By sliding the toggle button on the top right)
  3. Scroll down and under Drawing, tap these options one by one: Windows animation scale, Transition animation scale, and Animator duration scale
  4. Select "Animation scale 1x"

Does this help?

Android Left to Right slide animation, In your coding use intent like for right to left this. If you want to apply the animation on "activity" start. then write below code. make it slowly fades into view.xml. Defining the Animations. For our purposes, we’ll need four animations in total, and we’ll be defining them through XML. Of the four animations, there are really two groups. The first is to move a view from its current position to a position out of view, and the second is to bring a view in from out of view.

overridePendingTransition should be called in the "target" activity. For example: Going from Activity A -> B, you would put the overridePendingTransition call in the onCreate of Activity B.

Keep in mind, if the user has disabled animation on a system level, you can't force animations to show.

EDIT:

An example would look like this:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    overridePendingTransition(R.anim.enter, R.anim.exit);
}

Animating Android Activities and Views with Left and Right Slide , Animations, when used correctly, can be a simple way to enhance the basic left and right sliding animations to your Views and Activities on Android. will ensure that the newly started Activity runs the enterAnimationId and  I know this is a really old post, however, I cannot for the life of me get the onUpNavigation to load the right to left slide animation (after the activity has been created). Everytime, no matter what, it does the left to right animation.

Try this code, it's working for me

To slide from right to left

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >
    <translate
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="500"
        android:fromXDelta="0%"
        android:toXDelta="-50%" >
    </translate>
</set>

To slide from left to right

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromXDelta="-50%"
    android:toXDelta="0%" >
</translate>

Start an activity using an animation, Start your Activity with Slide Animation. Rohit Singh this happens. You can achieve this in 3 simple steps SDK_INT>20) { Slide slide = new Slide(); slide.​setSlideEdge(Gravity.LEFT); slide. Give feedback and feel free to correct mistakes. Slide animation can be applied to activity transitions by calling overridePendingTransition and passing animation resources for enter and exit activities. Slide animations can be slid right, slide left, slide up and slide down.

This is the perfect code for me Slideinleft

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

Slideinright

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

In Activity

Intent intent = new Intent(getApplicationContext(),termcondionactivity.class);
Bundle bndlAnimation = ActivityOptions.makeCustomAnimation(getApplicationContext(), R.anim.slideinleft, R.anim.slideinright).toBundle();

startActivity(intent, bndlAnimation);

Slide Animation Between Activites - Android Studio Tutorial, but when I try and animate the finish on the activity it is still doing the default right to left slide. I first tried defining the out animation when I start the activity as  I am trying to start an activity with a custom transition animation. The only way I have found out so far to do this (without using onPendingTransition() in the previous activity) is to use a custom theme on the activity and define either activityOpenEnterAnimation, taskOpenEnterAnimation, windowEnterAnimation or windowAnimationStyle to set the

Android studio tutorial, When you start an activity or finish the current activity the transition between the the animation resources for sliding the screen from left to right and vice versa. Can I change the Android startActivity() transition animation? If you always want to the same transition animation for the activity Is it common for the left

Start your Activity with Slide Animation - Rohit Singh, demonstrates how do I create left to right side animation in android. To run the app from android studio, open one of your project's activity  Slide Animation Between Activites - Android Studio Tutorial This feature is not available right now. Please try again later. Open a Fragment with an Animation + Communicate with Activity

How can I add an animation to the activity finish(), Then we will learn how to apply them globally to our whole app by creating a seperate theme in our styles.xml file and apply it to our app theme with the windowAnimationStyle attribute. To add the animations, right-click on anim -> New -> Animation resource file.

Comments
  • what to write to start the activity & target activity ?
  • Absolutely. I'll add that too
  • @Mike can we use the built in android.R.anim.slide_in_left and android.R.anim.slide_out_right?
  • first two animations can be reused for the back transition, just swap them? @Mike
  • @abdu try it :)
  • what to write in target activity to achieve that ?
  • please see edit for an example to add to your Activity A and B