日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

TabLayout中的Tab.setCustomView左右有空隙,TabLayout下划线间隙设置,下划线长度设置

發布時間:2023/12/10 编程问答 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 TabLayout中的Tab.setCustomView左右有空隙,TabLayout下划线间隙设置,下划线长度设置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

間隙設置為零?

因為當我們引入TabLayout時就已經默認tabPaddingStart為12dp,tabPaddingEnd為12dp.才會導致不能填滿的原因,這時我們只需要修改樣式或者屬性即可。

xmlns:app="http://schemas.android.com/apk/res-auto"

app:tabPaddingStart="0dp" app:tabPaddingEnd="0dp"

間隙大小設置,下劃線長度設置?

<com.google.android.material.tabs.TabLayoutandroid:layout_below="@+id/topli11"android:id="@+id/activity_tablayoutt"android:layout_width="match_parent"android:layout_height="@dimen/normal_110dp"android:background="@color/white"app:tabBackground="@null"app:tabRippleColor="@null"app:tabIndicatorColor="#4065E0"app:tabIndicatorHeight="@dimen/normal_5dp"app:tabIndicatorFullWidth="false"app:tabPaddingStart="@dimen/normal_70dp"app:tabPaddingEnd="@dimen/normal_70dp"app:tabMaxWidth="@dimen/normal_305dp"/>

?

<com.google.android.material.tabs.TabLayoutandroid:layout_below="@+id/topli11"android:id="@+id/activity_tablayoutt"android:layout_width="match_parent"android:layout_height="@dimen/normal_110dp"android:background="@color/white"app:tabBackground="@null"app:tabRippleColor="@null"app:tabIndicatorColor="#4065E0"app:tabIndicatorHeight="@dimen/normal_4dp"app:tabMaxWidth="@dimen/normal_180dp" />

?

方法二——api28以下使用

tabLayout.post(new Runnable() {@Overridepublic void run() {setIndicator(tabLayout);} });

?-----------------------------------------------------------------------------

/*** 設置tabLayout下劃線的寬*/ public static void setIndicator(TabLayout tabs) {Class<?> tabLayout = tabs.getClass();Field tabStrip = null;try {tabStrip = tabLayout.getDeclaredField("slidingTabIndicator");} catch (NoSuchFieldException e) {e.printStackTrace();}tabStrip.setAccessible(true);LinearLayout llTab = null;try {llTab = (LinearLayout) tabStrip.get(tabs);} catch (IllegalAccessException e) {e.printStackTrace();}//因為我想要的效果是 字多寬線就多寬,所以測量mTextView的寬度for (int i = 0, count = llTab.getChildCount(); i < count; i++) {//獲取tabViewView tabView = llTab.getChildAt(i);//拿到tabView的mTextView屬性Field mTextViewField = null;try {//獲取tabView的textView屬性mTextViewField = tabView.getClass().getDeclaredField("textView");} catch (NoSuchFieldException e) {e.printStackTrace();}mTextViewField.setAccessible(true);TextView textView = null;try {textView = (TextView) mTextViewField.get(tabView);} catch (IllegalAccessException e) {e.printStackTrace();}tabView.setPadding(0, 0, 0, 0);//獲取textview寬度int textWidth = 0;textWidth = textView.getWidth();if (textWidth == 0) {textView.measure(0, 0);textWidth = textView.getMeasuredWidth();}//獲取tabview寬度int tabWidth = 0;tabWidth = tabView.getWidth();if (tabWidth == 0) {tabView.measure(0, 0);tabWidth = tabView.getMeasuredWidth();}//設置下劃線margin值LinearLayout.LayoutParams tabViewParams = (LinearLayout.LayoutParams) tabView.getLayoutParams();int margin = (tabWidth - textWidth) / 2;tabViewParams.leftMargin = margin;tabViewParams.rightMargin = margin;tabView.setLayoutParams(tabViewParams);}}

總結

以上是生活随笔為你收集整理的TabLayout中的Tab.setCustomView左右有空隙,TabLayout下划线间隙设置,下划线长度设置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。