Scrolling between screens

0

I want to scroll between different screens. For example, create an equal scrolling of the mobile or desktop menu that when pulled one will occupy the space of the other. How can I do this?

    
asked by anonymous 26.03.2014 / 18:33

1 answer

3

Create a folder named "anim" in the "res" directory. La in, create the files:

slide_in_left_transition.xml

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

slide_in_right_transition.xml

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

slide_out_left_transition.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <translate
        android:duration="400"
        android:fromXDelta="100%"
        android:fromYDelta="0%"
        android:toXDelta="0%"
        android:toYDelta="0%" />

</set>

slide_out_right_transition.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <translate
        android:duration="400"
        android:fromXDelta="0%"
        android:fromYDelta="0%"
        android:toXDelta="100%"
        android:toYDelta="0%" />

</set>

Now when you want to make the animation go ahead, call the overridePendingTransition() method after giving startActivity , for example:

Intent i = new Intent(Activity1.this, Activity2.class);
startActivity(i);
overridePendingTransition(R.anim.slide_out_left_transition, R.anim.slide_in_right_transition);

Now to do the opposite effect, put overridePendingTransition(R.anim.slide_in_left_transition, R.anim.slide_out_right_transition); soon after closing the activity, either after a finish(); or in the event of the back button of the cell phone (see example below).

@Override
public void onBackPressed() {
    super.onBackPressed();
    overridePendingTransition(R.anim.slide_in_left_transition, R.anim.slide_out_right_transition);
}
    
26.03.2014 / 18:45