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