Skip to content

Commit b7128e7

Browse files
committed
fix bug: CommonTabLayout first setCurrentTab() cause indicator not show
1 parent 143bb94 commit b7128e7

File tree

8 files changed

+42
-38
lines changed

8 files changed

+42
-38
lines changed

CHNAGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,8 @@ Version 1.4.2 *(2015-12-9)*
4747

4848
Version 1.4.4 *(2015-12-11)*
4949
----------------------------
50+
* fix bug: CommonTabLayout first setCurrentTab() cause indicator not show
51+
52+
Version 1.4.6 *(2015-12-11)*
53+
----------------------------
5054
* fix bug: CommonTabLayout first setCurrentTab() cause indicator not show

FlycoTabLayout_Lib/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ apply plugin: 'com.android.library'
33
//apply plugin: 'com.jfrog.bintray'
44

55
// 这个version是区分library版本的,因此当我们需要更新library时记得修改这个version
6-
version = "1.4.4"
6+
version = "1.4.6"
77
android {
88
compileSdkVersion 23
99
buildToolsVersion "22.0.1"
1010

1111
defaultConfig {
1212
minSdkVersion 8
1313
targetSdkVersion 23
14-
versionCode 144
14+
versionCode 146
1515
versionName version
1616
}
1717
buildTypes {

FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/CommonTabLayout.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ private void addTab(final int position, View tabView) {
242242
public void onClick(View v) {
243243
int position = (Integer) v.getTag();
244244
if (currentTab != position) {
245-
isFirstSet = false;
246245
setCurrentTab(position);
247246
if (listener != null) {
248247
listener.onTabSelect(position);
@@ -327,16 +326,22 @@ private void calcOffset() {
327326
lp.left = lastTabView.getLeft();
328327
lp.right = lastTabView.getRight();
329328

330-
valueAnimator.setObjectValues(lp, cp);
331-
if (indicatorBounceEnable) {
332-
valueAnimator.setInterpolator(interpolator);
333-
}
329+
// Log.d("AAA", "lp--->" + lp.left + "&" + lp.right);
330+
// Log.d("AAA", "cp--->" + cp.left + "&" + cp.right);
331+
if (lp.left == cp.left && lp.right == cp.right) {
332+
invalidate();
333+
} else {
334+
valueAnimator.setObjectValues(lp, cp);
335+
if (indicatorBounceEnable) {
336+
valueAnimator.setInterpolator(interpolator);
337+
}
334338

335-
if (indicatorAnimDuration < 0) {
336-
indicatorAnimDuration = indicatorBounceEnable ? 500 : 250;
339+
if (indicatorAnimDuration < 0) {
340+
indicatorAnimDuration = indicatorBounceEnable ? 500 : 250;
341+
}
342+
valueAnimator.setDuration(indicatorAnimDuration);
343+
valueAnimator.start();
337344
}
338-
valueAnimator.setDuration(indicatorAnimDuration);
339-
valueAnimator.start();
340345
}
341346

342347
private void calcIndicatorRect() {
@@ -363,6 +368,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
363368
IndicatorPoint p = (IndicatorPoint) animation.getAnimatedValue();
364369
indicatorRect.left = (int) p.left;
365370
indicatorRect.right = (int) p.right;
371+
366372
if (indicatorWidth < 0) { //indicatorWidth小于0时,原jpardogo's PagerSlidingTabStrip
367373

368374
} else {//indicatorWidth大于0时,圆角矩形以及三角形
@@ -375,7 +381,6 @@ public void onAnimationUpdate(ValueAnimator animation) {
375381
}
376382

377383
private boolean isFirstDraw = true;
378-
private boolean isFirstSet = true;
379384

380385
@Override
381386
protected void onDraw(Canvas canvas) {
@@ -481,12 +486,7 @@ public void setCurrentTab(int currentTab) {
481486
fragmentChangeManager.setFragments(currentTab);
482487
}
483488
if (indicatorAnimEnable) {
484-
if (isFirstSet) {
485-
invalidate();
486-
isFirstSet = false;
487-
} else {
488-
calcOffset();
489-
}
489+
calcOffset();
490490
} else {
491491
invalidate();
492492
}

FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SegmentTabLayout.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.support.v4.app.Fragment;
1313
import android.support.v4.app.FragmentActivity;
1414
import android.util.AttributeSet;
15+
import android.util.Log;
1516
import android.util.SparseArray;
1617
import android.util.TypedValue;
1718
import android.view.Gravity;
@@ -198,7 +199,6 @@ private void addTab(final int position, View tabView) {
198199
public void onClick(View v) {
199200
int position = (Integer) v.getTag();
200201
if (currentTab != position) {
201-
isFirstSet = false;
202202
setCurrentTab(position);
203203
if (listener != null) {
204204
listener.onTabSelect(position);
@@ -257,16 +257,22 @@ private void calcOffset() {
257257
lp.left = lastTabView.getLeft();
258258
lp.right = lastTabView.getRight();
259259

260-
valueAnimator.setObjectValues(lp, cp);
261-
if (indicatorBounceEnable) {
262-
valueAnimator.setInterpolator(interpolator);
263-
}
260+
// Log.d("AAA", "lp--->" + lp.left + "&" + lp.right);
261+
// Log.d("AAA", "cp--->" + cp.left + "&" + cp.right);
262+
if (lp.left == cp.left && lp.right == cp.right) {
263+
invalidate();
264+
} else {
265+
valueAnimator.setObjectValues(lp, cp);
266+
if (indicatorBounceEnable) {
267+
valueAnimator.setInterpolator(interpolator);
268+
}
264269

265-
if (indicatorAnimDuration < 0) {
266-
indicatorAnimDuration = indicatorBounceEnable ? 500 : 250;
270+
if (indicatorAnimDuration < 0) {
271+
indicatorAnimDuration = indicatorBounceEnable ? 500 : 250;
272+
}
273+
valueAnimator.setDuration(indicatorAnimDuration);
274+
valueAnimator.start();
267275
}
268-
valueAnimator.setDuration(indicatorAnimDuration);
269-
valueAnimator.start();
270276
}
271277

272278
private void calcIndicatorRect() {
@@ -331,7 +337,6 @@ public void onAnimationUpdate(ValueAnimator animation) {
331337
}
332338

333339
private boolean isFirstDraw = true;
334-
private boolean isFirstSet = true;
335340

336341
@Override
337342
protected void onDraw(Canvas canvas) {
@@ -398,12 +403,7 @@ public void setCurrentTab(int currentTab) {
398403
fragmentChangeManager.setFragments(currentTab);
399404
}
400405
if (indicatorAnimEnable) {
401-
if (isFirstSet) {
402-
invalidate();
403-
isFirstSet = false;
404-
} else {
405-
calcOffset();
406-
}
406+
calcOffset();
407407
} else {
408408
invalidate();
409409
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ dependencies{
4545
compile 'com.android.support:support-v4:23.1.1'
4646
compile 'com.nineoldandroids:library:2.4.0'
4747
compile 'com.flyco.roundview:FlycoRoundView_Lib:1.1.2@aar'
48-
compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.4.4@aar'
48+
compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.4.6@aar'
4949
}
5050
```
5151

README_CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ dependencies{
4444
compile 'com.android.support:support-v4:23.1.1'
4545
compile 'com.nineoldandroids:library:2.4.0'
4646
compile 'com.flyco.roundview:FlycoRoundView_Lib:1.1.2@aar'
47-
compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.4.4@aar'
47+
compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.4.6@aar'
4848
}
4949
```
5050

app/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ dependencies {
2323
compile fileTree(dir: 'libs', include: ['*.jar'])
2424
compile 'com.android.support:appcompat-v7:23.1.1'
2525
compile project(':FlycoTabLayout_Lib')
26-
27-
// compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.4.4@aar'
26+
// compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.4.6@aar'
2827
// compile 'com.flyco.roundview:FlycoRoundView_Lib:1.1.2@aar'
2928
// compile 'com.nineoldandroids:library:2.4.0'
3029
}

app/src/main/java/com/flyco/tablayoutsamples/ui/CommonTabActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public void onTabReselect(int position) {
108108
}
109109
});
110110
tl_8.setCurrentTab(2);
111+
tl_3.setCurrentTab(1);
111112

112113
//显示未读红点
113114
tl_1.showDot(2);

0 commit comments

Comments
 (0)