본문 바로가기

ANDROID

Android UI - Animation (Transition)

1. SharedElements

   - Activity 혹은 Fragment 간에 화면이 전환 할때,

     콘텐츠가 이어지는 것을 볼수가 있다. 

    (ex : 프로필 사진을 확대해서 보거나, 이미지 목록형 화면에서 사용하기에 적합하다.)

(1) 전달 하는쪽 kt (어트리뷰트 선언 하는것을 권장) (리스트)

<!-- profile_item_photo.xml -->
<ImageView android:transitionName="photo" />
    
<!-- viewer_activity.xml -->
<ImageView android:transitionName="photo" />

//ProfileAcitivity.kt
val intnet = Intent(this, ViewerActivity::class.java)
intent.putExtra("resId", resId)
ActivityCompat.startActivity(
	this, intent,
    ActivityOptionsCompat.makeSceneTransitionAnimation(this, view, view.transitionName)
).toBundle()

(2) 전달 받는쪽 kt (표시)

// ViewerActivity.kt
override fun onCreate(savedInstanceState: Bundle?) 
{
	window.sharedElementEnterTransition =
    TransitionSet().apply {
    	interpolator = OvershootInterpolator(0.7f) // 통통 튀는 효과
        ordering = TransitionSet.ORDERING_TOGETHER
        addTransition(ChangeBounds().apply {
        	pathMotion = ArcMotion()
        })
        addTransition(ChangeTransform())
        addTransition(ChangeClipBounds())
        addTransition(ChangeImageTransform())
    }
    super.onCreate(savedInstanceState)
}

2. View Animation

  - 뷰가 이동할때 주어지는 애니메이션 (ViewPager 같은 느낌)

// In Activity
activity.overridePendingTransition (
	R.anim.slide_in_right,
    R.anim.slide_out.left
)

// In Fragemtn
fragmentManager.beginTransaction ()
	.setCustomAnimations(
	R.anim.slide_in_right,
    R.anim.slide_out.left
).replate(...)
.commit()

 

 

출처 : https://droidknights.github.io/2020/

 

Droidknights 2020

 

droidknights.github.io

https://github.com/fornewid/DroidKnights-2020-Sample

 

fornewid/DroidKnights-2020-Sample

Android UI에 Animation 들이붓기 🌈🌈 (드로이드나이츠 2020 세션 샘플) - fornewid/DroidKnights-2020-Sample

github.com

https://www.youtube.com/watch?v=-QiYB_PSg3o