From 17d95e269ca27919dda5db9f8f98d68ff46819d5 Mon Sep 17 00:00:00 2001 From: BaoZhou <107630221@qq.comgit> Date: Wed, 8 May 2019 16:02:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9TabView=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlycoTabLayout_Lib/build.gradle | 13 +++-- FlycoTabLayout_Lib/jitpack.gradle | 3 + .../com/flyco/tablayout/CommonTabLayout.java | 55 ++++++++++++++----- app/build.gradle | 16 +++--- .../ui/CommonTabActivity.java | 2 +- .../ui/SegmentTabActivity.java | 6 +- build.gradle | 10 +++- gradle/wrapper/gradle-wrapper.properties | 2 +- 8 files changed, 74 insertions(+), 33 deletions(-) create mode 100644 FlycoTabLayout_Lib/jitpack.gradle diff --git a/FlycoTabLayout_Lib/build.gradle b/FlycoTabLayout_Lib/build.gradle index 166f8c62..19feac06 100644 --- a/FlycoTabLayout_Lib/build.gradle +++ b/FlycoTabLayout_Lib/build.gradle @@ -1,16 +1,17 @@ apply plugin: 'com.android.library' +apply from: 'jitpack.gradle' //apply plugin: 'com.github.dcendents.android-maven' //apply plugin: 'com.jfrog.bintray' // 这个version是区分library版本的,因此当我们需要更新library时记得修改这个version version = "2.1.2" android { - compileSdkVersion 25 - buildToolsVersion "25.0.1" + compileSdkVersion 28 + buildToolsVersion "28.0.3" defaultConfig { - minSdkVersion 11 - targetSdkVersion 25 + minSdkVersion 18 + targetSdkVersion 28 versionCode 212 versionName version } @@ -23,8 +24,8 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:support-v4:25.1.0' + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:support-v4:28.0.0' } //def siteUrl = 'https://github.com/H07000223' // 项目的主页 diff --git a/FlycoTabLayout_Lib/jitpack.gradle b/FlycoTabLayout_Lib/jitpack.gradle new file mode 100644 index 00000000..e55696e4 --- /dev/null +++ b/FlycoTabLayout_Lib/jitpack.gradle @@ -0,0 +1,3 @@ +apply plugin: 'com.github.dcendents.android-maven' + +group = 'com.github.BzCoder' \ No newline at end of file diff --git a/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/CommonTabLayout.java b/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/CommonTabLayout.java index b0db9cd1..bb490b85 100644 --- a/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/CommonTabLayout.java +++ b/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/CommonTabLayout.java @@ -34,7 +34,9 @@ import java.util.ArrayList; -/** 没有继承HorizontalScrollView不能滑动,对于ViewPager无依赖 */ +/** + * 没有继承HorizontalScrollView不能滑动,对于ViewPager无依赖 + */ public class CommonTabLayout extends FrameLayout implements ValueAnimator.AnimatorUpdateListener { private Context mContext; private ArrayList mTabEntitys = new ArrayList<>(); @@ -42,7 +44,9 @@ public class CommonTabLayout extends FrameLayout implements ValueAnimator.Animat private int mCurrentTab; private int mLastTab; private int mTabCount; - /** 用于绘制显示器 */ + /** + * 用于绘制显示器 + */ private Rect mIndicatorRect = new Rect(); private GradientDrawable mIndicatorDrawable = new GradientDrawable(); @@ -59,7 +63,9 @@ public class CommonTabLayout extends FrameLayout implements ValueAnimator.Animat private boolean mTabSpaceEqual; private float mTabWidth; - /** indicator */ + /** + * indicator + */ private int mIndicatorColor; private float mIndicatorHeight; private float mIndicatorWidth; @@ -73,17 +79,23 @@ public class CommonTabLayout extends FrameLayout implements ValueAnimator.Animat private boolean mIndicatorBounceEnable; private int mIndicatorGravity; - /** underline */ + /** + * underline + */ private int mUnderlineColor; private float mUnderlineHeight; private int mUnderlineGravity; - /** divider */ + /** + * divider + */ private int mDividerColor; private float mDividerWidth; private float mDividerPadding; - /** title */ + /** + * title + */ private static final int TEXT_BOLD_NONE = 0; private static final int TEXT_BOLD_WHEN_SELECT = 1; private static final int TEXT_BOLD_BOTH = 2; @@ -93,7 +105,9 @@ public class CommonTabLayout extends FrameLayout implements ValueAnimator.Animat private int mTextBold; private boolean mTextAllCaps; - /** icon */ + /** + * icon + */ private boolean mIconVisible; private int mIconGravity; private float mIconWidth; @@ -102,7 +116,9 @@ public class CommonTabLayout extends FrameLayout implements ValueAnimator.Animat private int mHeight; - /** anim */ + /** + * anim + */ private ValueAnimator mValueAnimator; private OvershootInterpolator mInterpolator = new OvershootInterpolator(1.5f); @@ -201,13 +217,17 @@ public void setTabData(ArrayList tabEntitys) { notifyDataSetChanged(); } - /** 关联数据支持同时切换fragments */ + /** + * 关联数据支持同时切换fragments + */ public void setTabData(ArrayList tabEntitys, FragmentActivity fa, int containerViewId, ArrayList fragments) { mFragmentChangeManager = new FragmentChangeManager(fa.getSupportFragmentManager(), containerViewId, fragments); setTabData(tabEntitys); } - /** 更新数据 */ + /** + * 更新数据 + */ public void notifyDataSetChanged() { mTabsContainer.removeAllViews(); this.mTabCount = mTabEntitys.size(); @@ -230,10 +250,17 @@ public void notifyDataSetChanged() { updateTabStyles(); } - /** 创建并添加tab */ + /** + * 创建并添加tab + */ private void addTab(final int position, View tabView) { TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title); - tv_tab_title.setText(mTabEntitys.get(position).getTabTitle()); + if (mTabEntitys.get(position).getTabTitle().isEmpty()) { + tv_tab_title.setVisibility(View.GONE); + } else { + tv_tab_title.setVisibility(View.VISIBLE); + tv_tab_title.setText(mTabEntitys.get(position).getTabTitle()); + } ImageView iv_tab_icon = (ImageView) tabView.findViewById(R.id.iv_tab_icon); iv_tab_icon.setImageResource(mTabEntitys.get(position).getTabUnselectedIcon()); @@ -885,7 +912,9 @@ public void setMsgMargin(int position, float leftPadding, float bottomPadding) { } } - /** 当前类只提供了少许设置未读消息属性的方法,可以通过该方法获取MsgView对象从而各种设置 */ + /** + * 当前类只提供了少许设置未读消息属性的方法,可以通过该方法获取MsgView对象从而各种设置 + */ public MsgView getMsgView(int position) { if (position >= mTabCount) { position = mTabCount - 1; diff --git a/app/build.gradle b/app/build.gradle index f2f86d4d..7ffd538b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion "25.0.2" + compileSdkVersion 28 + buildToolsVersion "28.0.3" defaultConfig { applicationId "com.flyco.tablayoutsamples" - minSdkVersion 11 - targetSdkVersion 25 + minSdkVersion 18 + targetSdkVersion 28 versionCode 1 versionName "1.0" } @@ -20,12 +20,12 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:25.1.0' -// compile project(':FlycoTabLayout_Lib') + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation project(':FlycoTabLayout_Lib') //--->support 3.0+ - compile 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar' +// implementation 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar' //--->support 2.2+ // compile 'com.flyco.tablayout:FlycoTabLayout_Lib:2.0.0@aar' // compile 'com.nineoldandroids:library:2.4.0' diff --git a/app/src/main/java/com/flyco/tablayoutsamples/ui/CommonTabActivity.java b/app/src/main/java/com/flyco/tablayoutsamples/ui/CommonTabActivity.java index b898c2ce..fecae6d7 100644 --- a/app/src/main/java/com/flyco/tablayoutsamples/ui/CommonTabActivity.java +++ b/app/src/main/java/com/flyco/tablayoutsamples/ui/CommonTabActivity.java @@ -27,7 +27,7 @@ public class CommonTabActivity extends AppCompatActivity { private ArrayList mFragments = new ArrayList<>(); private ArrayList mFragments2 = new ArrayList<>(); - private String[] mTitles = {"首页", "消息", "联系人", "更多"}; + private String[] mTitles = {"", "消息", "联系人", "更多"}; private int[] mIconUnselectIds = { R.mipmap.tab_home_unselect, R.mipmap.tab_speech_unselect, R.mipmap.tab_contact_unselect, R.mipmap.tab_more_unselect}; diff --git a/app/src/main/java/com/flyco/tablayoutsamples/ui/SegmentTabActivity.java b/app/src/main/java/com/flyco/tablayoutsamples/ui/SegmentTabActivity.java index 9ac154cc..18edf7f3 100644 --- a/app/src/main/java/com/flyco/tablayoutsamples/ui/SegmentTabActivity.java +++ b/app/src/main/java/com/flyco/tablayoutsamples/ui/SegmentTabActivity.java @@ -21,9 +21,9 @@ public class SegmentTabActivity extends AppCompatActivity { private ArrayList mFragments = new ArrayList<>(); private ArrayList mFragments2 = new ArrayList<>(); - private String[] mTitles = {"首页", "消息"}; - private String[] mTitles_2 = {"首页", "消息", "联系人"}; - private String[] mTitles_3 = {"首页", "消息", "联系人", "更多"}; + private String[] mTitles = {"", "消息"}; + private String[] mTitles_2 = {"", "消息", "联系人"}; + private String[] mTitles_3 = {"", "消息", "联系人", "更多"}; private View mDecorView; private SegmentTabLayout mTabLayout_3; diff --git a/build.gradle b/build.gradle index 062f3830..a79a223e 100644 --- a/build.gradle +++ b/build.gradle @@ -2,20 +2,28 @@ buildscript { repositories { + google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.3' + classpath 'com.android.tools.build:gradle:3.3.2' + classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' // classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' // classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } + + configurations.all { + resolutionStrategy.cacheChangingModulesFor 0, 'seconds' + } } allprojects { repositories { + google() jcenter() + maven { url 'https://jitpack.io' } // maven { // url "http://dl.bintray.com/h07000223/maven" // } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 77c260b9..966a3285 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip