Skip to content

Commit

Permalink
fix bug: attr tl_indicator_width_equal_title sometime invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
H07000223 committed Nov 11, 2015
1 parent 0bed8ae commit 5cffc97
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 13 deletions.
6 changes: 5 additions & 1 deletion CHNAGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ Version 1.3.4 *(2015-11-5)*

Version 1.3.6 *(2015-11-10)*
----------------------------
* new add attr tl_indicator_width_equal_title
* new add attr tl_indicator_width_equal_title

Version 1.4.0 *(2015-11-11)*
----------------------------
* fix bug: attr tl_indicator_width_equal_title sometime invalid
4 changes: 2 additions & 2 deletions FlycoTabLayout_Lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ apply plugin: 'com.android.library'
//apply plugin: 'com.jfrog.bintray'

// 这个version是区分library版本的,因此当我们需要更新library时记得修改这个version
version = "1.3.6"
version = "1.4.0"
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"

defaultConfig {
minSdkVersion 8
targetSdkVersion 23
versionCode 136
versionCode 140
versionName version
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,30 +358,52 @@ private void updateTabSelection(int position) {
}
}

private float margin;

private void calcIndicatorRect() {
View currentTabView = tabsContainer.getChildAt(this.currentTab);
float left = currentTabView.getLeft();
float right = currentTabView.getRight();

//for indicatorWidthEqualTitle
if (indicatorStyle == STYLE_NORMAL && indicatorWidthEqualTitle) {
TextView tab_title = (TextView) currentTabView.findViewById(R.id.tv_tab_title);
textPaint.setTextSize(textsize);
float textWidth = textPaint.measureText(tab_title.getText().toString());
margin = (right - left - textWidth) / 2;
}

if (this.currentTab < tabCount - 1) {
View nextTabView = tabsContainer.getChildAt(this.currentTab + 1);
final float nextTabLeft = nextTabView.getLeft();
final float nextTabRight = nextTabView.getRight();
float nextTabLeft = nextTabView.getLeft();
float nextTabRight = nextTabView.getRight();

left = left + currentPositionOffset * (nextTabLeft - left);
right = right + currentPositionOffset * (nextTabRight - right);

//for indicatorWidthEqualTitle
if (indicatorStyle == STYLE_NORMAL && indicatorWidthEqualTitle) {
TextView next_tab_title = (TextView) nextTabView.findViewById(R.id.tv_tab_title);
textPaint.setTextSize(textsize);
float nextTextWidth = textPaint.measureText(next_tab_title.getText().toString());
float nextMargin = (nextTabRight - nextTabLeft - nextTextWidth) / 2;
margin = margin + currentPositionOffset * (nextMargin - margin);
}
}

indicatorRect.left = (int) left;
indicatorRect.right = (int) right;
//for indicatorWidthEqualTitle
if (indicatorStyle == STYLE_NORMAL && indicatorWidthEqualTitle) {
indicatorRect.left = (int) (left + margin - 1);
indicatorRect.right = (int) (right - margin - 1);
}

tabRect.left = (int) left;
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 @@ -465,6 +487,7 @@ protected void onDraw(Canvas canvas) {

if (indicatorHeight > 0) {
indicatorDrawable.setColor(indicatorColor);

if (indicatorGravity == Gravity.BOTTOM) {
indicatorDrawable.setBounds(paddingLeft + (int) indicatorMarginLeft + indicatorRect.left,
height - (int) indicatorHeight - (int) indicatorMarginBottom,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies{
compile 'com.android.support:support-v4:23.1.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.flyco.roundview:FlycoRoundView_Lib:1.0.6@aar'
compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.3.6@aar'
compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.4.0@aar'
}
```
Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies{
compile 'com.android.support:support-v4:23.1.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.flyco.roundview:FlycoRoundView_Lib:1.0.6@aar'
compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.3.6@aar'
compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.4.0@aar'
}
```

Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
// compile project(':FlycoTabLayout_Lib')
compile project(':FlycoTabLayout_Lib')

compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.3.6@aar'
/* compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.4.0@aar'
compile 'com.flyco.roundview:FlycoRoundView_Lib:1.0.4@aar'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.nineoldandroids:library:2.4.0'*/
}

0 comments on commit 5cffc97

Please sign in to comment.