반응형
요즘 업무가 바쁘다보니, 게시글 작성이 뜸합니다.
방금 간단한 exception 을 잡게되어 짧게 글 작성합니다.
RecyclerView 의 adapter에서 item layout에
android:animateLayoutChanges="true"
를 적용하였습니다.
그런데, 아래와 같은 exception이 발생!!
java.lang.IllegalStateException: Page(s) contain a ViewGroup with a LayoutTransition (or animateLayoutChanges="true"), which interferes with the scrolling animation. Make sure to call getLayoutTransition().setAnimateParentHierarchy(false) on all ViewGroups with a LayoutTransition before an animation is started.
페이지에 LayoutTransitions가 포함된 경우 해당 LayoutTransitions에는 animateParentHierarchy가 false로 설정되어 있어야 합니다. 레이아웃 xml 파일에 animateLayoutChanges="true"인 ViewGroup이 있는 경우 LayoutTransition이 해당 ViewGroup에 자동으로 추가됩니다. xml 레이아웃을 확장한 후 해당 ViewGroup에서 getLayoutTransition().setAnimateParentHierarchy(false)를 수동으로 호출해야 합니다.
요런 내용인 것 같습니다.
내용처럼 setAnimateParentHierarchy(false) 를 해주면 된다고 합니다.
adapter의 item이기때문에 layout이 attached가 된 후에 호출해주어야 합니다.
inner class ViewHolder(
private val binding: ItemBinding
) : RecyclerView.ViewHolder(binding.root) {
init {
with(binding) {
itemView.doOnAttach {
(it as? ViewGroup)?.layoutTransition?.setAnimateParentHierarchy(false)
}
}
}
}
위의 코드와 같이 ViewHolder의 init() 에서 itemView의 doOnAttach가 호출된 후에 함수 호출하여 exception을 수정하였습니다.
끝!!!
반응형
'Android + Kotlin' 카테고리의 다른 글
[Android+kotlin] PagingDataAdapter 에서 삭제기능 구현하기 (0) | 2023.03.13 |
---|---|
[Android + Kotlin] Notification Trampolines 이슈 해결하기 (0) | 2023.02.24 |
[Android + Kotlin] TextView에 <a> tag URL링크 적용하기 (0) | 2023.02.22 |
[Android+Kotlin] 외부저장소 파일 목록 가져오기 (디렉토리 위치, 최신순) (0) | 2023.02.09 |
[Android+Kotlin] 외부저장소에 파일 저장하기(Android Q 이상) (0) | 2023.02.09 |