Simulate ViewPager transition with fragments but in activities

3

Assuming we have two activities, A and B.

I want that when you press an element (for example a button) of the activity A change to the activity B simulating the effect that has been implemented in the ViewPager when changing from one fragment to another, as an activity slides to one side and the other appears next.

That effect is what I would like to simulate, but instead of sliding or using tabs that happens when clicking any view and that it is between two activities and not two fragments.

I tried to do it with

overridePendingTransition(R.anim.slide_left_translate, R.anim.slide_left_translate);

Also with this:

Slide slide= new 
slide.setDuration(1000);
getWindow().setEnterTransition(slide);


Slide slide= new 
slide.setDuration(1000);
getWindow().setExitTransition(slide);

Writing those lines of code in activity A and activity B

But not if it is that I am using that code from above badly or it is done differently or it simply can not be done between two activities.

    
asked by borjis 24.10.2016 в 16:41
source

2 answers

4

Input

overridePendingTransition(R.anim.left_in, R.anim.left_out);

Departure

overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);

Animations

left_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromXDelta="50%p"
        android:toXDelta="0"
        android:duration="@android:integer/config_mediumAnimTime"/>
    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:duration="@android:integer/config_mediumAnimTime" />
</set>

left_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromXDelta="0"
        android:toXDelta="-50%p"
        android:duration="@android:integer/config_mediumAnimTime"/>
    <alpha
        android:fromAlpha="1.0"
        android:toAlpha="0.0"
        android:duration="@android:integer/config_mediumAnimTime" />
</set>
    
answered by 24.10.2016 / 16:51
source
1

I complement the answer of @Nicol_Israel_Olvera_Acosta

Transitions between activities using overridePendingTransition(anim_entrada,ani_salida)

startActivity(new Intent(MainActivity.this,ActivityB.class));
overridePendingTransition(R.anim.left_in, R.anim.left_out);

In the ActivityB when closing, make the inverse transition

@Override
public void onBackPressed() {
    super.onBackPressed();
    overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);

}
    
answered by 26.10.2016 в 12:38