Created
July 5, 2019 17:55
-
-
Save tiiime/6090292565d26ecdbd932cefd2999c5f to your computer and use it in GitHub Desktop.
DynamicModeTabLayout
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
class DynamicModeTabLayout : TabLayout { | |
constructor(context: Context?) : super(context) | |
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) | |
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) | |
override fun setupWithViewPager(viewPager: ViewPager?) { | |
super.setupWithViewPager(viewPager) | |
val view = getChildAt(0) ?: return | |
view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED) | |
val size = view.measuredWidth | |
if (size > measuredWidth) { | |
tabMode = MODE_SCROLLABLE | |
tabGravity = GRAVITY_CENTER | |
} else { | |
tabMode = MODE_FIXED | |
tabGravity = GRAVITY_FILL | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment