Android

transition animation 적용

그란. 2022. 8. 14. 15:42

SharedElement를 이용해서 애니메이션 적용하기 

 

LoginActivity -> RegisterActivity 

 

 

1. transitionName 지정 

  • 이 이름을 찾아서 그 뷰로 이동해주세요
<string name="register_transition_name">transitionName</string>

 

LoginActivity

<Button
    android:id="@+id/google"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:background="@drawable/bg_login_google"/>

<ImageView
    android:id="@+id/iv_google"
    android:src=""
    android:transitionName="@string/register_transition_name"/>

RegisterActivity 

<ImageView
    android:id="@+id/iv_social"
    android:transitionName="@string/register_transition_name"/>

 

 

2. Activity :테마 지정

<style name="Transition" parent="Theme.AppTheme">
    <item name="android:windowActivityTransitions">true</item>
</style>

 

<activity
    android:name=".view.onboard.login.LoginActivity"
    android:theme="@style/Theme.Dearmate.Transition">
    
<activity
    android:name=".view.onboard.register.RegisterActivity"
    android:theme="@style/Theme.Dearmate.Transition" />

 

onCreate 전에 추가

 

RegisterActivity

 override fun onCreate(savedInstanceState: Bundle?) {
    setEnterSharedElementCallback(MaterialContainerTransformSharedElementCallback())
    window.sharedElementEnterTransition = MaterialContainerTransform().apply {
        addTarget(getString(R.string.register_transition_name))
        duration = 600L
    }
    super.onCreate(savedInstanceState)
}

 

3. startActivity에 옵션 추가  

RegisterActivity에 startActivity지정

companion object { 

    fun startActivity(activity: Activity, view: View) {
        activity.startActivity(
            getIntent(activity),
            ActivityOptions.makeSceneTransitionAnimation(
                activity,
                view,
                activity.getString(R.string.register_transition_name)
            ).toBundle()
        )
    }
}

 

LoginActivitiy

RegisterActivity.startActivity(
    this@LoginActivity,
    viewDatabinding.ivGoogle
)

 

 

'Android' 카테고리의 다른 글

카카오톡 잠금화면 구현  (0) 2022.09.29
소셜 로그인 모듈화 과정 ( 추상화 및 액티비티 의존성 제거 )  (1) 2022.09.29
Room With Coroutine Flow  (0) 2022.07.30
DataStore 적용하기  (0) 2022.07.27
코루틴 공부  (0) 2022.07.18