0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Android Navigationでアニメーション付きで画面遷移させる

Last updated at Posted at 2020-10-23

config.xmlとアニメーション用のxmlを作成する

main/res/values/config.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="config_transitionAnimTime">400</integer>
</resources>
res/anim/slide_in_right.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="@integer/config_transitionAnimTime" />
    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:duration="@integer/config_transitionAnimTime" />
</set>
res/anim/slide_out_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="-50%p"
        android:duration="@integer/config_transitionAnimTime" />
    <alpha
        android:fromAlpha="1.0"
        android:toAlpha="0.0"
        android:duration="@integer/config_transitionAnimTime" />
</set>
res/anim/slide_in_left.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="@integer/config_transitionAnimTime" />
    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:duration="@integer/config_transitionAnimTime" />
</set>
res/anim/slide_out_right.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="@integer/config_transitionAnimTime" />
    <alpha
        android:fromAlpha="1.0"
        android:toAlpha="0.0"
        android:duration="@integer/config_transitionAnimTime" />
</set>

navigationファイルでアニメーションを設定する。

res/navigation/nav_graph.xml
        <action
            android:id="@+id/action_hogeFragment_to_fugaFragment"
            app:destination="@id/fugaFragment"
            app:enterAnim="@anim/slide_in_right"
            app:exitAnim="@anim/slide_out_left"
            app:popEnterAnim="@anim/slide_in_left"
            app:popExitAnim="@anim/slide_out_right" />
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?