Created
February 11, 2020 13:45
-
-
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 file contains hidden or 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
/** | |
* 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() | |
} |
@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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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