Android-TabLayout设置内容宽度以及下划线宽度


默认图:


效果图:


  
项目中使用到需要像今日头条那种实现顶部横向滑动标题功能,本人项目中使用TabLayout+ViewPager实现,

但是,实现后默认的TabLayout间距特别大,并且下划线,文字大小等很难实现,百度查阅了好多资料,并不好使,
最后才发现,其实特别简单,只是细节而已:
  1.设置TabLayout中各个条目之间的间距,利用app:tabPaddingEnd="10dp"和app:tabPaddingStart="10dp"即可实现,
但是,在实际显示中,并没有起作用,所以需要设置额外的属性app:tabGravity="fill",app:tabMinWidth="30dp"
  2、设置字体大小,需要在style中自定义tabTextAppearance属性TabLayoutTextStyle,具体如下

 

在xml中

         <android.support.design.widget.TabLayout
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    app:tabGravity="fill"
                    app:tabIndicatorColor="@color/Red"
                    app:tabMinWidth="30dp"
                    app:tabMode="scrollable"
                    app:tabPaddingEnd="10dp"
                    app:tabPaddingStart="10dp"
                    app:tabTextAppearance="@style/TabLayoutTextStyle"     
        />

style中

<style name="TabLayoutTextStyle" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textSize">16sp</item>
    </style>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM