Skip to content

Instantly share code, notes, and snippets.

@tiiime
Created July 5, 2019 17:55
Show Gist options
  • Save tiiime/6090292565d26ecdbd932cefd2999c5f to your computer and use it in GitHub Desktop.
Save tiiime/6090292565d26ecdbd932cefd2999c5f to your computer and use it in GitHub Desktop.
DynamicModeTabLayout
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