专业网站设计网站,株洲网站优化哪家强,如何不花钱做网站,小网站做几个关键词间隙设置为零
因为当我们引入TabLayout时就已经默认tabPaddingStart为12dp,tabPaddingEnd为12dp.才会导致不能填满的原因#xff0c;这时我们只需要修改样式或者属性即可。 xmlns:apphttp://schemas.android.com/apk/res-auto app:tabPaddingStart0dp这时我们只需要修改样式或者属性即可。 xmlns:apphttp://schemas.android.com/apk/res-auto app:tabPaddingStart0dp
app:tabPaddingEnd0dp
间隙大小设置下划线长度设置 com.google.android.material.tabs.TabLayoutandroid:layout_belowid/topli11android:idid/activity_tablayouttandroid:layout_widthmatch_parentandroid:layout_heightdimen/normal_110dpandroid:backgroundcolor/whiteapp:tabBackgroundnullapp:tabRippleColornullapp:tabIndicatorColor#4065E0app:tabIndicatorHeightdimen/normal_5dpapp:tabIndicatorFullWidthfalseapp:tabPaddingStartdimen/normal_70dpapp:tabPaddingEnddimen/normal_70dpapp:tabMaxWidthdimen/normal_305dp/ com.google.android.material.tabs.TabLayoutandroid:layout_belowid/topli11android:idid/activity_tablayouttandroid:layout_widthmatch_parentandroid:layout_heightdimen/normal_110dpandroid:backgroundcolor/whiteapp:tabBackgroundnullapp:tabRippleColornullapp:tabIndicatorColor#4065E0app:tabIndicatorHeightdimen/normal_4dpapp:tabMaxWidthdimen/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);}}