How to switch from one screen to another with animation

I just looked at the twitter app and seemed to have a nice transition when switching from one screen to another. I am trying to get the same behavior in my application.

I am currently moving between screens:

startActivityForResult(new Intent(getApplicationContext(), MyActivity.class), 1);

But in this way there is no transition between the screen. MyActivityjust appears on the screen.

+4
source share
2 answers

Animation with drawings:

, . anim /res/. drawables, :

anim_left_to_right.xml

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

anim_right_to_left.xml

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

overridePendingTransition() startActivity() ( startActivityForResult()):

startActivityForResult(new Intent(getApplicationContext(), MyActivity.class), 1);
overridePendingTransition(anim_left_to_right, anim_right_to_left);

:

" startActivity", : Vine, onCreate() out onPause(). .

+5

overridePendingTransition(entry_anim, exit_anim) startActivity().

xml.

+3

Source: https://habr.com/ru/post/1540035/


All Articles