From 5cffc976a4cd4dc1edd69543c178ded1536b4c05 Mon Sep 17 00:00:00 2001 From: H07000223 <867318349@qq.com> Date: Wed, 11 Nov 2015 13:49:13 +0800 Subject: [PATCH] fix bug: attr tl_indicator_width_equal_title sometime invalid --- CHNAGELOG.md | 6 +++- FlycoTabLayout_Lib/build.gradle | 4 +-- .../com/flyco/tablayout/SlidingTabLayout.java | 33 ++++++++++++++++--- README.md | 2 +- README_CN.md | 2 +- app/build.gradle | 6 ++-- 6 files changed, 40 insertions(+), 13 deletions(-) diff --git a/CHNAGELOG.md b/CHNAGELOG.md index 7e740cbf..78e29f24 100644 --- a/CHNAGELOG.md +++ b/CHNAGELOG.md @@ -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 \ No newline at end of file +* 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 \ No newline at end of file diff --git a/FlycoTabLayout_Lib/build.gradle b/FlycoTabLayout_Lib/build.gradle index e68e0356..1e758749 100644 --- a/FlycoTabLayout_Lib/build.gradle +++ b/FlycoTabLayout_Lib/build.gradle @@ -3,7 +3,7 @@ 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" @@ -11,7 +11,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 23 - versionCode 136 + versionCode 140 versionName version } buildTypes { diff --git a/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SlidingTabLayout.java b/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SlidingTabLayout.java index fbf0cdab..29ef4dcb 100644 --- a/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SlidingTabLayout.java +++ b/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SlidingTabLayout.java @@ -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; @@ -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, diff --git a/README.md b/README.md index 0245bd07..4e86cb31 100644 --- a/README.md +++ b/README.md @@ -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' } ``` diff --git a/README_CN.md b/README_CN.md index 8060ffe1..2fc30b6e 100644 --- a/README_CN.md +++ b/README_CN.md @@ -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' } ``` diff --git a/app/build.gradle b/app/build.gradle index 6cfc2767..417998b8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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'*/ }