Created
May 6, 2023 07:12
-
-
Save ZZANZU/646e9e0507f4de1a218fa26a2ea9a03c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mViewpager.registerOnPageChangeCallback(object: OnPageChangeCallback() { | |
override fun onPageSelected(position: Int) { | |
// height를 wrap_content가 되도록 설정 | |
val view = (getChildAt(0) as RecyclerView).layoutManager?.findViewByPosition(position) // 표시된 아이템의 뷰 객체 | |
view?.post { // UI 스레드에서 해당 뷰 height를 다시 설정해서 그려줌 | |
val wMeasureSpec = | |
View.MeasureSpec.makeMeasureSpec(view.width, View.MeasureSpec.EXACTLY) | |
val hMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED) | |
view.measure(wMeasureSpec, hMeasureSpec) | |
if (getChildAt(0).layoutParams.height != view.measuredHeight) { | |
getChildAt(0).layoutParams = (getChildAt(0).layoutParams).also { lp -> | |
lp.height = view.measuredHeight | |
} | |
} | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment