Skip to content

Commit

Permalink
new added attr tl_indicator_width_equal_title
Browse files Browse the repository at this point in the history
  • Loading branch information
H07000223 committed Nov 10, 2015
1 parent 6ad499a commit ab7c6bb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,15 @@ protected void onDraw(Canvas canvas) {
if (indicatorHeight > 0) {
indicatorDrawable.setColor(indicatorColor);
if (indicatorGravity == Gravity.BOTTOM) {
indicatorDrawable.setBounds(paddingLeft + indicatorRect.left,
(int) (height - indicatorHeight), paddingLeft + indicatorRect.right, height);
indicatorDrawable.setBounds(paddingLeft + (int) indicatorMarginLeft + indicatorRect.left,
height - (int) indicatorHeight - (int) indicatorMarginBottom,
paddingLeft + indicatorRect.right - (int) indicatorMarginRight,
height - (int) indicatorMarginBottom);
} else {
indicatorDrawable.setBounds(paddingLeft + indicatorRect.left,
0, paddingLeft + indicatorRect.right, (int) indicatorHeight);
indicatorDrawable.setBounds(paddingLeft + (int) indicatorMarginLeft + indicatorRect.left,
(int) indicatorMarginTop,
paddingLeft + indicatorRect.right - (int) indicatorMarginRight,
(int) indicatorHeight + (int) indicatorMarginTop);
}
indicatorDrawable.setCornerRadius(indicatorCornerRadius);
indicatorDrawable.draw(canvas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class SlidingTabLayout extends HorizontalScrollView implements ViewPager.
private float indicatorMarginRight;
private float indicatorMarginBottom;
private float indicatorGravity;
private boolean indicatorWidthEqualTitle;

/** underline */
private int underlineColor;
Expand Down Expand Up @@ -140,6 +141,7 @@ private void obtainAttributes(Context context, AttributeSet attrs) {
indicatorMarginRight = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_margin_right, dp2px(0));
indicatorMarginBottom = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_margin_bottom, dp2px(indicatorStyle == STYLE_BLOCK ? 7 : 0));
indicatorGravity = ta.getInt(R.styleable.SlidingTabLayout_tl_indicator_gravity, Gravity.BOTTOM);
indicatorWidthEqualTitle = ta.getBoolean(R.styleable.SlidingTabLayout_tl_indicator_width_equal_title, false);

underlineColor = ta.getColor(R.styleable.SlidingTabLayout_tl_underline_color, Color.parseColor("#ffffff"));
underlineHeight = ta.getDimension(R.styleable.SlidingTabLayout_tl_underline_height, dp2px(0));
Expand Down Expand Up @@ -377,7 +379,9 @@ private void calcIndicatorRect() {
tabRect.right = (int) right;

if (indicatorWidth < 0) { //indicatorWidth小于0时,原jpardogo's PagerSlidingTabStrip

if (indicatorStyle == STYLE_NORMAL && indicatorWidthEqualTitle) {//只有在STYLE_NORMAL并且indicatorWidth小于零有效
indicatorMarginLeft = indicatorMarginRight = tabPadding - 1;
}
} else {//indicatorWidth大于0时,圆角矩形以及三角形
float indicatorLeft = currentTabView.getLeft() + (currentTabView.getWidth() - indicatorWidth) / 2;

Expand Down Expand Up @@ -462,11 +466,15 @@ protected void onDraw(Canvas canvas) {
if (indicatorHeight > 0) {
indicatorDrawable.setColor(indicatorColor);
if (indicatorGravity == Gravity.BOTTOM) {
indicatorDrawable.setBounds(paddingLeft + indicatorRect.left,
(int) (height - indicatorHeight), paddingLeft + indicatorRect.right, height);
indicatorDrawable.setBounds(paddingLeft + (int) indicatorMarginLeft + indicatorRect.left,
height - (int) indicatorHeight - (int) indicatorMarginBottom,
paddingLeft + indicatorRect.right - (int) indicatorMarginRight,
height - (int) indicatorMarginBottom);
} else {
indicatorDrawable.setBounds(paddingLeft + indicatorRect.left,
0, paddingLeft + indicatorRect.right, (int) indicatorHeight);
indicatorDrawable.setBounds(paddingLeft + (int) indicatorMarginLeft + indicatorRect.left,
(int) indicatorMarginTop,
paddingLeft + indicatorRect.right - (int) indicatorMarginRight,
(int) indicatorHeight + (int) indicatorMarginTop);
}
indicatorDrawable.setCornerRadius(indicatorCornerRadius);
indicatorDrawable.draw(canvas);
Expand Down Expand Up @@ -544,6 +552,11 @@ public void setIndicatorMargin(float indicatorMarginLeft, float indicatorMarginT
invalidate();
}

public void setIndicatorWidthEqualTitle(boolean indicatorWidthEqualTitle) {
this.indicatorWidthEqualTitle = indicatorWidthEqualTitle;
invalidate();
}

public void setUnderlineGravity(float underlineGravity) {
this.underlineGravity = underlineGravity;
invalidate();
Expand Down
3 changes: 3 additions & 0 deletions FlycoTabLayout_Lib/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<enum name="TRIANGLE" value="1"/>
<enum name="BLOCK" value="2"/>
</attr>
<!-- 设置显示器长度与title一样长,只有在STYLE_NORMAL并且indicatorWidth小于零有效-->
<attr name="tl_indicator_width_equal_title" format="boolean"/>

<!-- underline -->
<!-- 设置下划线颜色 -->
Expand Down Expand Up @@ -77,6 +79,7 @@
<attr name="tl_indicator_corner_radius"/>
<attr name="tl_indicator_gravity"/>
<attr name="tl_indicator_style"/>
<attr name="tl_indicator_width_equal_title"/>

<!-- underline -->
<attr name="tl_underline_color"/>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_sliding_tab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
tl:tl_divider_width="1dp"
tl:tl_indicator_color="#000000"
tl:tl_indicator_height="1.5dp"
tl:tl_indicator_width_equal_title="true"
tl:tl_tab_padding="22dp"
tl:tl_tab_space_equal="true"
tl:tl_textSelectColor="#000000"
Expand Down

0 comments on commit ab7c6bb

Please sign in to comment.