Foggy day
Android(Kotlin) - Setting the viewpager2 height according to the height of the items 본문
Android
Android(Kotlin) - Setting the viewpager2 height according to the height of the items
jinhan38 2021. 4. 18. 20:57
private fun setViewPager2Height(){
viewPager2.setPageTransformer { page, position ->
updatePagerHeightForChild(page, viewPager2)
}
}
private fun updatePagerHeightForChild(view: View, pager: ViewPager2) {
view.post {
val wMeasureSpec = View.MeasureSpec.makeMeasureSpec(view.width, View.MeasureSpec.EXACTLY)
val hMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
view.measure(wMeasureSpec, hMeasureSpec)
pager.layoutParams = (pager.layoutParams).also { lp -> lp.height = view.measuredHeight }
pager.invalidate()
}
}
'Android' 카테고리의 다른 글
[Android] fragment onbackpressed callback (0) | 2021.05.28 |
---|---|
Android(Kotlin) - 공휴일, 주말 날짜 얻어오기 (0) | 2021.04.18 |
Android - screen flickering whilefragment transaction (0) | 2021.04.03 |
Android(Kotlin) - RxKotlin -2 : Map, flatMap (0) | 2021.03.23 |
Android(Kotlin) - RxKotlin -2 : Observable (0) | 2021.03.23 |