在开发中,遇到当tablayout的标题文字过长时,会导致标题换行,如下图
我的xml如下
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/tablayout"
android:layout_width="match_parent"
android:layout_height="88px"
android:background="@color/color_white"
app:tabMaxWidth="2000px"
app:tabIndicatorColor="@color/color_text_07_red"
app:tabMode="scrollable">
</android.support.design.widget.TabLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:background="@color/color_divide_01_grey" />
<android.support.v4.view.ViewPager
android:id="@+id/胜利iewpager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
</LinearLayout>
尝试了很多办法,最后用发只需要在tablayout中设置tabMaxWidth属性就能解决,具体大小根据你最长的标题长度设置即可。