How to make Tablayout indicator and text the same width

In my application, I work with tablayout. everything works fine, but I want the tablayout text and indicator line to be the same size.

but the width of the pointer left and right takes up extra space. how to remove extra space or make it equal width.

make fit

thanks

+5
source share
1 answer

I will find a solution from http://blog.csdn.net/u013134391/article/details/70833903

public void reflex(final TabLayout tabLayout){ tabLayout.post(new Runnable() { @Override public void run() { try { LinearLayout mTabStrip = (LinearLayout) tabLayout.getChildAt(0); int dp10 = dip2px(tabLayout.getContext(), 10); for (int i = 0; i < mTabStrip.getChildCount(); i++) { View tabView = mTabStrip.getChildAt(i); Field mTextViewField = tabView.getClass().getDeclaredField("mTextView"); mTextViewField.setAccessible(true); TextView mTextView = (TextView) mTextViewField.get(tabView); tabView.setPadding(0, 0, 0, 0); int width = 0; width = mTextView.getWidth(); if (width == 0) { mTextView.measure(0, 0); width = mTextView.getMeasuredWidth(); } LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) tabView.getLayoutParams(); params.width = width ; params.leftMargin = dp10; params.rightMargin = dp10; tabView.setLayoutParams(params); tabView.invalidate(); } } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } }); } 
0
source

All Articles