-
-
Save safaorhan/1a541af729c7657426138d18b87d5bd4 to your computer and use it in GitHub Desktop.
/** | |
* Disables the child attach listener so that inflated children with wrap_content heights can pass. | |
* | |
* This is very fragile and depends on the implementation details of [ViewPager2]. | |
* | |
* @see ViewPager2.enforceChildFillListener (the removed listener) | |
*/ | |
private fun ViewPager2.hackMatchParentCheckInViewPager() { | |
(getChildAt(0) as RecyclerView).clearOnChildAttachStateChangeListeners() | |
} |
what all other changes are required to achieve this.
It's been a long time I came up with this. You need to be sure that your inflated children uses wrap_content height.
thanks @safaorhan , it solved my problem.
Glad to hear that!
Thanks this work for me ,when we want to use viewpager as Book ' pages. There are different kinds of page height. Sometimes , we need to scroll action when page is too long :3 At that time, just wrap your viewpager's item layout with NestedScroll View..
Thanks to @safaorhan
@ChinGyi2019 Glad to hear that it helped!
Our use case was similar, we were showing three items with different heights in ViewPager.
I was getting a calculation of all child views to calculate the one with the biggest height. So I was dynamically changing the height of the ViewPager and triggering a second measurement round
@muth0mi you need to do other changes as well. This is to just bypass the runtime check in the ViewPager