@@ -86,13 +86,15 @@ public interface IconTabProvider {
8686 private int indicatorColor = 0xffFF811C ; // 指示器颜色
8787 private int underlineColor = 0xffCECECE ; // 下划线颜色
8888 private int dividerColor = 0xFF811C ; // 分割线颜色
89- private int indicatorPadding = 10 ; //指示器 左右内边距
89+ private float indicatorPadding = 10 ; //指示器 左右内边距
9090
9191 private boolean shouldExpand = false ;//FF811C
9292 private boolean textAllCaps = true ;
93+ private boolean isFixedIndicatorWidth = false ;
9394
9495 private int scrollOffset = 52 ;
9596 private int indicatorHeight = 0 ; // 指示器高度
97+ private int indicatorWidth = 0 ; // 指示器宽度
9698 private int underlineHeight = 0 ; // 下划线高度
9799 private int dividerPadding = 6 ; // 分割线
98100 private int tabPadding = 22 ;
@@ -140,15 +142,14 @@ public PagerSlidingTabStrip(Context context, AttributeSet attrs,
140142 TypedValue .COMPLEX_UNIT_DIP , scrollOffset , dm );
141143 indicatorHeight = (int ) TypedValue .applyDimension (
142144 TypedValue .COMPLEX_UNIT_DIP , indicatorHeight , dm );
145+ indicatorWidth = (int ) TypedValue .applyDimension (TypedValue .COMPLEX_UNIT_DIP , indicatorWidth , dm );
143146 underlineHeight = (int ) TypedValue .applyDimension (
144147 TypedValue .COMPLEX_UNIT_DIP , underlineHeight , dm );
145148 dividerPadding = (int ) TypedValue .applyDimension (
146149 TypedValue .COMPLEX_UNIT_DIP , dividerPadding , dm );
147- tabPadding = (int ) TypedValue .applyDimension (
148- TypedValue .COMPLEX_UNIT_DIP , tabPadding , dm );
149150 tabPaddingr = (int ) TypedValue .applyDimension (
150151 TypedValue .COMPLEX_UNIT_DIP , tabPaddingr , dm );
151- indicatorPadding = ( int ) TypedValue .applyDimension (
152+ indicatorPadding = TypedValue .applyDimension (
152153 TypedValue .COMPLEX_UNIT_DIP , indicatorPadding , dm );
153154 dividerWidth = (int ) TypedValue .applyDimension (
154155 TypedValue .COMPLEX_UNIT_DIP , dividerWidth , dm );
@@ -170,15 +171,17 @@ public PagerSlidingTabStrip(Context context, AttributeSet attrs,
170171 a = context .obtainStyledAttributes (attrs , R .styleable .PagerSlidingTabStrip );
171172
172173 indicatorColor = a .getColor (R .styleable .PagerSlidingTabStrip_indicatorColor , indicatorColor );
173- indicatorPadding = a .getDimensionPixelSize (R .styleable .PagerSlidingTabStrip_indicatorPaddingLeftRight , indicatorPadding );
174+ indicatorPadding = a .getDimensionPixelSize (R .styleable .PagerSlidingTabStrip_indicatorPaddingLeftRight , ( int ) indicatorPadding );
174175 underlineColor = a .getColor (R .styleable .PagerSlidingTabStrip_underlineColor , underlineColor );
175176 dividerColor = a .getColor (R .styleable .PagerSlidingTabStrip_dividerColor , dividerColor );
176177 indicatorHeight = a .getDimensionPixelSize (R .styleable .PagerSlidingTabStrip_indicatorHeight , indicatorHeight );
178+ indicatorWidth = a .getDimensionPixelSize (R .styleable .PagerSlidingTabStrip_indicatorWidth , indicatorWidth );
177179 underlineHeight = a .getDimensionPixelSize (R .styleable .PagerSlidingTabStrip_underlineHeight , underlineHeight );
178180 dividerPadding = a .getDimensionPixelSize (R .styleable .PagerSlidingTabStrip_dividerPadding , dividerPadding );
179181 tabPadding = a .getDimensionPixelSize (R .styleable .PagerSlidingTabStrip_tabPaddingLeftRight , tabPadding );
180182 tabBackgroundResId = a .getResourceId (R .styleable .PagerSlidingTabStrip_tabBackground , tabBackgroundResId );
181183 shouldExpand = a .getBoolean (R .styleable .PagerSlidingTabStrip_shouldExpand , shouldExpand );
184+ isFixedIndicatorWidth = a .getBoolean (R .styleable .PagerSlidingTabStrip_isFixedIndicatorWidth , isFixedIndicatorWidth );
182185 scrollOffset = a .getDimensionPixelSize (R .styleable .PagerSlidingTabStrip_scrollOffset , scrollOffset );
183186// textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_textAllCaps, textAllCaps);
184187 tabTextSize = a .getDimensionPixelSize (R .styleable .PagerSlidingTabStrip_tabDefTextSize , tabTextSize );
@@ -316,30 +319,18 @@ private void updateTabStyles() {
316319
317320 View v = tabsContainer .getChildAt (i );
318321
319- v .setLayoutParams (defaultTabLayoutParams );
320322 v .setBackgroundResource (tabBackgroundResId );
321323
322324 if (v instanceof TextView ) {
323325
324326 TextView tab = (TextView ) v ;
325327 tab .setTypeface (tabTypeface , tabTypefaceStyle );
326- v .setPadding (tabPadding , 0 , tabPadding , 0 );
327328 if (currentIndex == i ) {
328329 tab .setTextSize (TypedValue .COMPLEX_UNIT_PX , tabTextSizer );
329330 tab .setTextColor (tabTextColorr );
330- // if (shouldExpand) {
331- // v.setPadding(tabPadding, 0, tabPadding, 0);
332- // } else {
333- // v.setPadding(tabPadding, 0, tabPadding, 0);
334- // }
335331 } else {
336332 tab .setTextSize (TypedValue .COMPLEX_UNIT_PX , tabTextSize );
337333 tab .setTextColor (tabTextColor );
338- // if (shouldExpand) {
339- // v.setPadding(0, 0, 0, 0);
340- // } else {
341- // v.setPadding(0, 0, 0, 0);
342- // }
343334 }
344335 // setAllCaps() is only available from API 14, so the upper case
345336 // is made manually if we are on a
@@ -361,24 +352,27 @@ private void updateTabStyles() {
361352 protected void onMeasure (int widthMeasureSpec , int heightMeasureSpec ) {
362353 super .onMeasure (widthMeasureSpec , heightMeasureSpec );
363354
364- if (!shouldExpand
365- || MeasureSpec .getMode (widthMeasureSpec ) == MeasureSpec .UNSPECIFIED ) {
366- return ;
367- }
355+ // if (!shouldExpand
356+ // || MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.UNSPECIFIED) {
357+ // return;
358+ // }
368359
369360 int myWidth = getMeasuredWidth ();
370361 int childWidth = 0 ;
371362 for (int i = 0 ; i < pageCount ; i ++) {
372- childWidth += tabsContainer .getChildAt (i ).getMeasuredWidth ();
363+ childWidth += tabsContainer .getChildAt (i ).getMeasuredWidth () + ( tabPadding * 2 ) ;
373364 }
374365
375366 if (!checkedTabWidths && childWidth > 0 && myWidth > 0 ) {
376-
377- if (childWidth <= myWidth ) {
378- for (int i = 0 ; i < pageCount ; i ++) {
379- tabsContainer .getChildAt (i ).setLayoutParams (
380- expandedTabLayoutParams );
381- }
367+ LinearLayout .LayoutParams lp ;
368+ if (childWidth > myWidth ) {
369+ lp = defaultTabLayoutParams ;
370+ } else {
371+ // if (myWidth / pageCount < maxItemWidth) expandedTabLayoutParamsWrap else
372+ lp = expandedTabLayoutParams ;
373+ }
374+ for (int i = 0 ; i < pageCount ; i ++) {
375+ tabsContainer .getChildAt (i ).setLayoutParams (lp );
382376 }
383377
384378 checkedTabWidths = true ;
@@ -436,7 +430,9 @@ protected void onDraw(Canvas canvas) {
436430 lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset )
437431 * lineRight );
438432 }
439-
433+ if (isFixedIndicatorWidth ) {
434+ indicatorPadding = (lineRight - lineLeft - indicatorWidth ) / 2 ;
435+ }
440436 canvas .drawRect (lineLeft + indicatorPadding , height - indicatorHeight , lineRight - indicatorPadding , height ,
441437 rectPaint );
442438
0 commit comments