转载请注明出处:http://blog.csdn.net/crazy1235/article/details/71425135
使用TabLayout的时候,有些tab的文字比较多时,会出现与其他tab的文字大小不一致的情况!
TabLayout 继承自 HorizontalScrollView
内部有几个关键的类:
SlidingTabStrip – TabLayout的唯一子View
Tab – 子item的实体类,包含text, icon, customView等属性
TabView – 每个Tab的布局
ViewPagerOnTabSelectedListener – – 监听滑动
TabLayoutOnPageChangeListener – 监听滑动
关于每个tab的文字大小的设置关键代码就在 TabView.onMeasure() 之中!
@Override
public void onMeasure(final int origWidthMeasureSpec, final int origHeightMeasureSpec) {
// ...
// We need to switch the text size based on whether the text is spanning 2 lines or not
if (mTextView != null) {
final Resources res = getResources();
float textSize = mTabTextSize;
int maxLines = mDefaultMaxLines;
if (mIconView != null && mIconView.getVisibility() == VISIBLE) {
// If the icon view is being displayed, we limit the text to 1 line
maxLines = 1;
} else if (m