PagerSlidingTabStrip设置滑动条宽度

设置宽度需要修改控件的属性

1.在attrs中,添加属性pstsIndicatorWidth



    
        
    



2.在类PagerSlidingTabStrip的构造方法中,添加
DisplayMetrics dm = getResources().getDisplayMetrics();

indicatorWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorWidth, dm);

indicatorWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorWidth, indicatorWidth);

3.在onDraw方法中


canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
修改为
canvas.drawRect(lineLeft + (lineRight-lineLeft-indicatorWidth)/2, height - indicatorHeight, lineRight-(lineRight-lineLeft-indicatorWidth)/2, height, rectPaint);

到此修改完毕,设置属性即可
    





你可能感兴趣的:(PagerSlidingTabStrip设置滑动条宽度)