본문 바로가기
Android (Kotlin)/mini projects

animation 화면 슬라이드 전환 구현

by 키윤 2023. 12. 29.

<slide_in_from_bottom.xml>

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

<slide_out_to_top.xml>

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

<slide_in_from_left.xml>

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

<slide_in_from_right.xml>

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

<slide_out_to_left.xml>

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

<slide_out_to_right.xml>

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

Kotlin Code

start() / launch() 뒤에

overridePendingTransition(R.anim.slide_in_from_bottom, R.anim.slide_out_to_top)