From e9e617cafedb3f4c5b2eb005c0fc7990b4b5b96c Mon Sep 17 00:00:00 2001 From: zengwendi <10483479@qq.com> Date: Mon, 22 Oct 2018 17:50:37 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlycoTabLayout_Lib/build.gradle | 39 ++++- .../com/flyco/tablayout/SlidingTabLayout.java | 152 +++++++++++++++--- .../src/main/res/layout/layout_tab.xml | 2 +- .../src/main/res/values/attrs.xml | 3 +- app/build.gradle | 16 +- app/src/main/AndroidManifest.xml | 7 +- .../tablayoutsamples/ui/SildingActivity.kt | 53 ++++++ .../ui/SimpleHomeActivity.java | 7 +- .../ui/SlidingTabActivity.java | 7 +- .../main/res/drawable/shape_bt_red_fillet.xml | 11 ++ .../main/res/drawable/shape_bt_tow_fillet.xml | 11 ++ app/src/main/res/layout/activity_sliding.xml | 22 +++ .../main/res/layout/activity_sliding_tab.xml | 17 +- build.gradle | 8 +- gradle/wrapper/gradle-wrapper.properties | 4 +- 15 files changed, 314 insertions(+), 45 deletions(-) create mode 100644 app/src/main/java/com/flyco/tablayoutsamples/ui/SildingActivity.kt create mode 100644 app/src/main/res/drawable/shape_bt_red_fillet.xml create mode 100644 app/src/main/res/drawable/shape_bt_tow_fillet.xml create mode 100644 app/src/main/res/layout/activity_sliding.xml diff --git a/FlycoTabLayout_Lib/build.gradle b/FlycoTabLayout_Lib/build.gradle index 166f8c62..2adfa859 100644 --- a/FlycoTabLayout_Lib/build.gradle +++ b/FlycoTabLayout_Lib/build.gradle @@ -1,12 +1,23 @@ apply plugin: 'com.android.library' + +apply plugin: 'com.novoda.bintray-release'//添加 //apply plugin: 'com.github.dcendents.android-maven' //apply plugin: 'com.jfrog.bintray' // 这个version是区分library版本的,因此当我们需要更新library时记得修改这个version -version = "2.1.2" + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2' + } +} + android { compileSdkVersion 25 - buildToolsVersion "25.0.1" + buildToolsVersion '26.0.2' defaultConfig { minSdkVersion 11 @@ -27,6 +38,30 @@ dependencies { compile 'com.android.support:support-v4:25.1.0' } +// 打包源码jar +task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' +} + + +allprojects { + tasks.withType(Javadoc) { + options.encoding = "UTF-8" + } +} +task javadoc(type: Javadoc) { + source = android.sourceSets.main.java.srcDirs + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + options.encoding = "UTF-8" +} +publish { + artifactId = 'FlycoTabLayout_Lib' // library的名字 + groupId = 'com.vclicai'// 包名 + publishVersion = '1.0.5' // 版本 + website = 'https://github.com/H07000223/FlycoTabLayout' + userOrg = 'vclicai' +} //def siteUrl = 'https://github.com/H07000223' // 项目的主页 //def gitUrl = 'https://github.com/H07000223' // Git仓库的url //group = "com.flyco.tablayout" // Maven Group ID for the artifact,一般填你唯一的包名 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 9ab7e5ed..cf57359e 100644 --- a/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SlidingTabLayout.java +++ b/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SlidingTabLayout.java @@ -7,6 +7,7 @@ import android.graphics.Paint; import android.graphics.Path; import android.graphics.Rect; +import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.os.Bundle; import android.os.Parcelable; @@ -14,6 +15,7 @@ import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.content.ContextCompat; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.util.AttributeSet; @@ -33,18 +35,25 @@ import java.util.ArrayList; import java.util.Collections; -/** 滑动TabLayout,对于ViewPager的依赖性强 */ +/** + * 滑动TabLayout,对于ViewPager的依赖性强 + */ public class SlidingTabLayout extends HorizontalScrollView implements ViewPager.OnPageChangeListener { private Context mContext; private ViewPager mViewPager; private ArrayList mTitles; + private ArrayList mTabState; private LinearLayout mTabsContainer; private int mCurrentTab; private float mCurrentPositionOffset; private int mTabCount; - /** 用于绘制显示器 */ + /** + * 用于绘制显示器 + */ private Rect mIndicatorRect = new Rect(); - /** 用于实现滚动居中 */ + /** + * 用于实现滚动居中 + */ private Rect mTabRect = new Rect(); private GradientDrawable mIndicatorDrawable = new GradientDrawable(); @@ -61,7 +70,9 @@ public class SlidingTabLayout extends HorizontalScrollView implements ViewPager. private boolean mTabSpaceEqual; private float mTabWidth; - /** indicator */ + /** + * indicator + */ private int mIndicatorColor; private float mIndicatorHeight; private float mIndicatorWidth; @@ -73,17 +84,23 @@ public class SlidingTabLayout extends HorizontalScrollView implements ViewPager. private int mIndicatorGravity; private boolean mIndicatorWidthEqualTitle; - /** 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; @@ -97,6 +114,11 @@ public class SlidingTabLayout extends HorizontalScrollView implements ViewPager. private int mHeight; private boolean mSnapOnTabClick; + private int mTabDefaultBackground; + private int mTabCompleteBackground; + private Drawable mTabDefaultDrawable; + private Drawable mTabCompleteDrawable; + public SlidingTabLayout(Context context) { this(context, null, 0); } @@ -164,11 +186,20 @@ private void obtainAttributes(Context context, AttributeSet attrs) { mTabSpaceEqual = ta.getBoolean(R.styleable.SlidingTabLayout_tl_tab_space_equal, false); mTabWidth = ta.getDimension(R.styleable.SlidingTabLayout_tl_tab_width, dp2px(-1)); mTabPadding = ta.getDimension(R.styleable.SlidingTabLayout_tl_tab_padding, mTabSpaceEqual || mTabWidth > 0 ? dp2px(0) : dp2px(20)); - + mTabDefaultBackground = ta.getResourceId(R.styleable.SlidingTabLayout_tl_tab_default_background, 0); + mTabCompleteBackground = ta.getResourceId(R.styleable.SlidingTabLayout_tl_tab_complete_background, 0); + if (mTabDefaultBackground > 0) { + mTabDefaultDrawable = ContextCompat.getDrawable(context, mTabDefaultBackground); + } + if (mTabCompleteBackground > 0) { + mTabCompleteDrawable = ContextCompat.getDrawable(context, mTabCompleteBackground); + } ta.recycle(); } - /** 关联ViewPager */ + /** + * 关联ViewPager + */ public void setViewPager(ViewPager vp) { if (vp == null || vp.getAdapter() == null) { throw new IllegalStateException("ViewPager or ViewPager adapter can not be NULL !"); @@ -181,7 +212,9 @@ public void setViewPager(ViewPager vp) { notifyDataSetChanged(); } - /** 关联ViewPager,用于不想在ViewPager适配器中设置titles数据的情况 */ + /** + * 关联ViewPager,用于不想在ViewPager适配器中设置titles数据的情况 + */ public void setViewPager(ViewPager vp, String[] titles) { if (vp == null || vp.getAdapter() == null) { throw new IllegalStateException("ViewPager or ViewPager adapter can not be NULL !"); @@ -204,7 +237,9 @@ public void setViewPager(ViewPager vp, String[] titles) { notifyDataSetChanged(); } - /** 关联ViewPager,用于连适配器都不想自己实例化的情况 */ + /** + * 关联ViewPager,用于连适配器都不想自己实例化的情况 + */ public void setViewPager(ViewPager vp, String[] titles, FragmentActivity fa, ArrayList fragments) { if (vp == null) { throw new IllegalStateException("ViewPager can not be NULL !"); @@ -222,12 +257,16 @@ public void setViewPager(ViewPager vp, String[] titles, FragmentActivity fa, Arr notifyDataSetChanged(); } - /** 更新数据 */ + /** + * 更新数据 + */ public void notifyDataSetChanged() { mTabsContainer.removeAllViews(); this.mTabCount = mTitles == null ? mViewPager.getAdapter().getCount() : mTitles.size(); View tabView; + mTabState = new ArrayList<>(); for (int i = 0; i < mTabCount; i++) { + mTabState.add(false); tabView = View.inflate(mContext, R.layout.layout_tab, null); CharSequence pageTitle = mTitles == null ? mViewPager.getAdapter().getPageTitle(i) : mTitles.get(i); addTab(i, pageTitle.toString(), tabView); @@ -245,11 +284,15 @@ public void addNewTab(String title) { CharSequence pageTitle = mTitles == null ? mViewPager.getAdapter().getPageTitle(mTabCount) : mTitles.get(mTabCount); addTab(mTabCount, pageTitle.toString(), tabView); this.mTabCount = mTitles == null ? mViewPager.getAdapter().getCount() : mTitles.size(); - + if (mTabState != null) { + mTabState.add(false); + } updateTabStyles(); } - /** 创建并添加tab */ + /** + * 创建并添加tab + */ private void addTab(final int position, String title, View tabView) { TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title); if (tv_tab_title != null) { @@ -262,15 +305,14 @@ public void onClick(View v) { int position = mTabsContainer.indexOfChild(v); if (position != -1) { if (mViewPager.getCurrentItem() != position) { + if (mListener != null) { + mListener.onTabSelect(position); + } if (mSnapOnTabClick) { mViewPager.setCurrentItem(position, false); } else { mViewPager.setCurrentItem(position); } - - if (mListener != null) { - mListener.onTabSelect(position); - } } else { if (mListener != null) { mListener.onTabReselect(position); @@ -334,7 +376,9 @@ public void onPageSelected(int position) { public void onPageScrollStateChanged(int state) { } - /** HorizontalScrollView滚到当前tab,并且居中显示 */ + /** + * HorizontalScrollView滚到当前tab,并且居中显示 + */ private void scrollToCurrentTab() { if (mTabCount <= 0) { return; @@ -442,7 +486,35 @@ protected void onDraw(Canvas canvas) { if (isInEditMode() || mTabCount <= 0) { return; } - + if (mTabDefaultDrawable != null) { + int centerY = mHeight / 2; + for (int i = 0; i < mTabCount; i++) { + View tab = mTabsContainer.getChildAt(i); + boolean tabState = mTabState.get(i) && mTabCompleteDrawable != null; + int drawableHeight = tabState ? mTabCompleteDrawable.getIntrinsicHeight() : mTabDefaultDrawable.getIntrinsicHeight(); + int drawableWidth = tabState ? mTabCompleteDrawable.getIntrinsicWidth() : mTabDefaultDrawable.getIntrinsicWidth(); + int top = centerY - drawableHeight / 2; + int bottom = centerY + drawableHeight / 2; + int centerX = tab.getLeft() + (tab.getRight() - tab.getLeft()) / 2 + getPaddingLeft(); + mTabCompleteDrawable.setBounds(centerX - drawableWidth / 2, + top, + centerX + drawableWidth / 2, + bottom); + if (tabState) { + mTabCompleteDrawable.setBounds(centerX - drawableWidth / 2, + top, + centerX + drawableWidth / 2, + bottom); + mTabCompleteDrawable.draw(canvas); + } else { + mTabDefaultDrawable.setBounds(centerX - drawableWidth / 2, + top, + centerX + drawableWidth / 2, + bottom); + mTabDefaultDrawable.draw(canvas); + } + } + } int height = getHeight(); int paddingLeft = getPaddingLeft(); // draw divider @@ -523,6 +595,34 @@ protected void onDraw(Canvas canvas) { } } + /** + * 设置tab完成状态 + * + * @param states + */ + public void setTabStateTabStateComplete(int... states) { + for (int state : states) { + if (state < mTabState.size()) { + mTabState.set(state, true); + } + } + invalidate(); + } + + /** + * 设置tab默认状态 + * + * @param states + */ + public void setTabStateTabStateDefault(int... states) { + for (int state : states) { + if (state < mTabState.size()) { + mTabState.set(state, false); + } + } + invalidate(); + } + //setter and getter public void setCurrentTab(int currentTab) { this.mCurrentTab = currentTab; @@ -799,7 +899,9 @@ public void showDot(int position) { showMsg(position, 0); } - /** 隐藏未读消息 */ + /** + * 隐藏未读消息 + */ public void hideMsg(int position) { if (position >= mTabCount) { position = mTabCount - 1; @@ -812,7 +914,9 @@ public void hideMsg(int position) { } } - /** 设置未读消息偏移,原点为文字的右上角.当控件高度固定,消息提示位置易控制,显示效果佳 */ + /** + * 设置未读消息偏移,原点为文字的右上角.当控件高度固定,消息提示位置易控制,显示效果佳 + */ public void setMsgMargin(int position, float leftPadding, float bottomPadding) { if (position >= mTabCount) { position = mTabCount - 1; @@ -831,7 +935,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/FlycoTabLayout_Lib/src/main/res/layout/layout_tab.xml b/FlycoTabLayout_Lib/src/main/res/layout/layout_tab.xml index 9a46415d..09ec781f 100644 --- a/FlycoTabLayout_Lib/src/main/res/layout/layout_tab.xml +++ b/FlycoTabLayout_Lib/src/main/res/layout/layout_tab.xml @@ -15,8 +15,8 @@ android:singleLine="true"/> - + + diff --git a/app/build.gradle b/app/build.gradle index f2f86d4d..d0027a15 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,8 +1,9 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' android { compileSdkVersion 25 - buildToolsVersion "25.0.2" + buildToolsVersion '26.0.2' defaultConfig { applicationId "com.flyco.tablayoutsamples" @@ -17,16 +18,23 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + lintOptions { + abortOnError false + } + } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:25.1.0' -// compile project(':FlycoTabLayout_Lib') + compile 'com.android.support:appcompat-v7:25.4.0' + compile project(':FlycoTabLayout_Lib') + compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" //--->support 3.0+ - compile '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' } +repositories { + mavenCentral() +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b9a3f790..4c53d3ed 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ + xmlns:android="http://schemas.android.com/apk/res/android" + package="com.flyco.tablayoutsamples"> + diff --git a/app/src/main/java/com/flyco/tablayoutsamples/ui/SildingActivity.kt b/app/src/main/java/com/flyco/tablayoutsamples/ui/SildingActivity.kt new file mode 100644 index 00000000..a27c8aab --- /dev/null +++ b/app/src/main/java/com/flyco/tablayoutsamples/ui/SildingActivity.kt @@ -0,0 +1,53 @@ +package com.flyco.tablayoutsamples.ui + +import android.os.Build +import android.os.Bundle +import android.support.annotation.RequiresApi +import android.support.v4.app.Fragment +import android.support.v4.app.FragmentManager +import android.support.v4.app.FragmentPagerAdapter +import android.support.v7.app.AppCompatActivity +import com.flyco.tablayout.CommonTabLayout +import com.flyco.tablayout.listener.CustomTabEntity +import com.flyco.tablayoutsamples.R +import com.flyco.tablayoutsamples.entity.TabEntity +import java.util.* + +/** + * Created by zengwendi on 2018/4/26. + */ + +class SildingActivity : AppCompatActivity() { + + private val mFragments = ArrayList() + private var mAdapter: MyPagerAdapter? = null + private val mTitles = arrayOf("自动投标", "散标", "债转") + private val mTabEntities = ArrayList() + + @RequiresApi(Build.VERSION_CODES.JELLY_BEAN) + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_sliding) + val tabEntitys = mTitles.mapTo(destination = ArrayList()) { + TabEntity(it, 0, 0) + } + var tab = findViewById(R.id.tl_6) as CommonTabLayout + tab.setTabData(tabEntitys) + + } + + private inner class MyPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) { + + override fun getCount(): Int { + return mFragments.size + } + + override fun getPageTitle(position: Int): CharSequence { + return mTitles[position] + } + + override fun getItem(position: Int): Fragment { + return mFragments[position] + } + } +} diff --git a/app/src/main/java/com/flyco/tablayoutsamples/ui/SimpleHomeActivity.java b/app/src/main/java/com/flyco/tablayoutsamples/ui/SimpleHomeActivity.java index 087c3e7a..0f9795d0 100644 --- a/app/src/main/java/com/flyco/tablayoutsamples/ui/SimpleHomeActivity.java +++ b/app/src/main/java/com/flyco/tablayoutsamples/ui/SimpleHomeActivity.java @@ -13,9 +13,9 @@ public class SimpleHomeActivity extends AppCompatActivity { private Context mContext = this; - private final String[] mItems = {"SlidingTabLayout", "CommonTabLayout", "SegmentTabLayout"}; + private final String[] mItems = {"SlidingTabLayout", "CommonTabLayout", "SegmentTabLayout","SlidingTabActivity"}; private final Class[] mClasses = {SlidingTabActivity.class, CommonTabActivity.class, - SegmentTabActivity.class}; + SegmentTabActivity.class,SildingActivity.class}; @Override protected void onCreate(Bundle savedInstanceState) { @@ -35,4 +35,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) setContentView(lv); } + + + } diff --git a/app/src/main/java/com/flyco/tablayoutsamples/ui/SlidingTabActivity.java b/app/src/main/java/com/flyco/tablayoutsamples/ui/SlidingTabActivity.java index 290c9b03..6232442a 100644 --- a/app/src/main/java/com/flyco/tablayoutsamples/ui/SlidingTabActivity.java +++ b/app/src/main/java/com/flyco/tablayoutsamples/ui/SlidingTabActivity.java @@ -23,8 +23,8 @@ public class SlidingTabActivity extends AppCompatActivity implements OnTabSelect private Context mContext = this; private ArrayList mFragments = new ArrayList<>(); private final String[] mTitles = { - "热门", "iOS", "Android" - , "前端", "后端", "设计", "工具资源" + "1", "2", "3" + , "4", "5","6","7","8","9","10" }; private MyPagerAdapter mAdapter; @@ -73,10 +73,11 @@ protected void onCreate(Bundle savedInstanceState) { tabLayout_6.setViewPager(vp); tabLayout_7.setViewPager(vp, mTitles); tabLayout_8.setViewPager(vp, mTitles, this, mFragments); - tabLayout_9.setViewPager(vp); + tabLayout_9.setViewPager(vp,mTitles); tabLayout_10.setViewPager(vp); vp.setCurrentItem(4); +// tabLayout_9.setTabStateTabStateComplete(1,4); tabLayout_1.showDot(4); tabLayout_3.showDot(4); diff --git a/app/src/main/res/drawable/shape_bt_red_fillet.xml b/app/src/main/res/drawable/shape_bt_red_fillet.xml new file mode 100644 index 00000000..90067e99 --- /dev/null +++ b/app/src/main/res/drawable/shape_bt_red_fillet.xml @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/app/src/main/res/drawable/shape_bt_tow_fillet.xml b/app/src/main/res/drawable/shape_bt_tow_fillet.xml new file mode 100644 index 00000000..64ad0aec --- /dev/null +++ b/app/src/main/res/drawable/shape_bt_tow_fillet.xml @@ -0,0 +1,11 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_sliding.xml b/app/src/main/res/layout/activity_sliding.xml new file mode 100644 index 00000000..e5b747ff --- /dev/null +++ b/app/src/main/res/layout/activity_sliding.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_sliding_tab.xml b/app/src/main/res/layout/activity_sliding_tab.xml index 3df558dd..695a1541 100644 --- a/app/src/main/res/layout/activity_sliding_tab.xml +++ b/app/src/main/res/layout/activity_sliding_tab.xml @@ -101,13 +101,22 @@ + tl:tl_indicator_color="#5490F4" + tl:tl_indicator_height="20dp" + tl:tl_indicator_margin_top="10dp" + tl:tl_indicator_style="BLOCK" + tl:tl_indicator_width="20dp" + tl:tl_tab_complete_background="@drawable/shape_bt_red_fillet" + tl:tl_tab_default_background="@drawable/shape_bt_tow_fillet" + tl:tl_tab_width="60dp" + tl:tl_textSelectColor="#ffffff" + tl:tl_textUnselectColor="#ffffff"/> + Date: Tue, 23 Oct 2018 12:00:19 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlycoTabLayout_Lib/build.gradle | 37 ++++- .../com/flyco/tablayout/SlidingTabLayout.java | 152 +++++++++++++++--- .../src/main/res/values/attrs.xml | 3 +- app/build.gradle | 17 +- app/src/main/AndroidManifest.xml | 18 ++- .../com/flyco/tablayoutsamples/entity/Demo.kt | 3 + .../tablayoutsamples/ui/SildingActivity.kt | 53 ++++++ .../ui/SimpleHomeActivity.java | 5 +- .../main/res/drawable/shape_bt_red_fillet.xml | 11 ++ .../main/res/drawable/shape_bt_tow_fillet.xml | 11 ++ app/src/main/res/layout/activity_sliding.xml | 22 +++ .../main/res/layout/activity_sliding_tab.xml | 17 +- build.gradle | 8 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 14 files changed, 310 insertions(+), 49 deletions(-) create mode 100644 app/src/main/java/com/flyco/tablayoutsamples/entity/Demo.kt create mode 100644 app/src/main/java/com/flyco/tablayoutsamples/ui/SildingActivity.kt create mode 100644 app/src/main/res/drawable/shape_bt_red_fillet.xml create mode 100644 app/src/main/res/drawable/shape_bt_tow_fillet.xml create mode 100644 app/src/main/res/layout/activity_sliding.xml diff --git a/FlycoTabLayout_Lib/build.gradle b/FlycoTabLayout_Lib/build.gradle index 166f8c62..7a84b1ac 100644 --- a/FlycoTabLayout_Lib/build.gradle +++ b/FlycoTabLayout_Lib/build.gradle @@ -1,16 +1,17 @@ apply plugin: 'com.android.library' +apply plugin: 'com.novoda.bintray-release'//添加 //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 26 + buildToolsVersion "26.0.2" defaultConfig { minSdkVersion 11 - targetSdkVersion 25 + targetSdkVersion 26 versionCode 212 versionName version } @@ -24,7 +25,35 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:support-v4:25.1.0' + compile 'com.android.support:support-v4:26.1.0' +} + + + + +// 打包源码jar +task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' +} + + +allprojects { + tasks.withType(Javadoc) { + options.encoding = "UTF-8" + } +} +task javadoc(type: Javadoc) { + source = android.sourceSets.main.java.srcDirs + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + options.encoding = "UTF-8" +} +publish { + artifactId = 'FlycoTabLayout_Lib' // library的名字 + groupId = 'com.vclicai'// 包名 + publishVersion = '1.0.6' // 版本 + website = 'https://github.com/H07000223/FlycoTabLayout' + userOrg = 'vclicai' } //def siteUrl = 'https://github.com/H07000223' // 项目的主页 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 9ab7e5ed..cf57359e 100644 --- a/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SlidingTabLayout.java +++ b/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SlidingTabLayout.java @@ -7,6 +7,7 @@ import android.graphics.Paint; import android.graphics.Path; import android.graphics.Rect; +import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.os.Bundle; import android.os.Parcelable; @@ -14,6 +15,7 @@ import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.content.ContextCompat; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.util.AttributeSet; @@ -33,18 +35,25 @@ import java.util.ArrayList; import java.util.Collections; -/** 滑动TabLayout,对于ViewPager的依赖性强 */ +/** + * 滑动TabLayout,对于ViewPager的依赖性强 + */ public class SlidingTabLayout extends HorizontalScrollView implements ViewPager.OnPageChangeListener { private Context mContext; private ViewPager mViewPager; private ArrayList mTitles; + private ArrayList mTabState; private LinearLayout mTabsContainer; private int mCurrentTab; private float mCurrentPositionOffset; private int mTabCount; - /** 用于绘制显示器 */ + /** + * 用于绘制显示器 + */ private Rect mIndicatorRect = new Rect(); - /** 用于实现滚动居中 */ + /** + * 用于实现滚动居中 + */ private Rect mTabRect = new Rect(); private GradientDrawable mIndicatorDrawable = new GradientDrawable(); @@ -61,7 +70,9 @@ public class SlidingTabLayout extends HorizontalScrollView implements ViewPager. private boolean mTabSpaceEqual; private float mTabWidth; - /** indicator */ + /** + * indicator + */ private int mIndicatorColor; private float mIndicatorHeight; private float mIndicatorWidth; @@ -73,17 +84,23 @@ public class SlidingTabLayout extends HorizontalScrollView implements ViewPager. private int mIndicatorGravity; private boolean mIndicatorWidthEqualTitle; - /** 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; @@ -97,6 +114,11 @@ public class SlidingTabLayout extends HorizontalScrollView implements ViewPager. private int mHeight; private boolean mSnapOnTabClick; + private int mTabDefaultBackground; + private int mTabCompleteBackground; + private Drawable mTabDefaultDrawable; + private Drawable mTabCompleteDrawable; + public SlidingTabLayout(Context context) { this(context, null, 0); } @@ -164,11 +186,20 @@ private void obtainAttributes(Context context, AttributeSet attrs) { mTabSpaceEqual = ta.getBoolean(R.styleable.SlidingTabLayout_tl_tab_space_equal, false); mTabWidth = ta.getDimension(R.styleable.SlidingTabLayout_tl_tab_width, dp2px(-1)); mTabPadding = ta.getDimension(R.styleable.SlidingTabLayout_tl_tab_padding, mTabSpaceEqual || mTabWidth > 0 ? dp2px(0) : dp2px(20)); - + mTabDefaultBackground = ta.getResourceId(R.styleable.SlidingTabLayout_tl_tab_default_background, 0); + mTabCompleteBackground = ta.getResourceId(R.styleable.SlidingTabLayout_tl_tab_complete_background, 0); + if (mTabDefaultBackground > 0) { + mTabDefaultDrawable = ContextCompat.getDrawable(context, mTabDefaultBackground); + } + if (mTabCompleteBackground > 0) { + mTabCompleteDrawable = ContextCompat.getDrawable(context, mTabCompleteBackground); + } ta.recycle(); } - /** 关联ViewPager */ + /** + * 关联ViewPager + */ public void setViewPager(ViewPager vp) { if (vp == null || vp.getAdapter() == null) { throw new IllegalStateException("ViewPager or ViewPager adapter can not be NULL !"); @@ -181,7 +212,9 @@ public void setViewPager(ViewPager vp) { notifyDataSetChanged(); } - /** 关联ViewPager,用于不想在ViewPager适配器中设置titles数据的情况 */ + /** + * 关联ViewPager,用于不想在ViewPager适配器中设置titles数据的情况 + */ public void setViewPager(ViewPager vp, String[] titles) { if (vp == null || vp.getAdapter() == null) { throw new IllegalStateException("ViewPager or ViewPager adapter can not be NULL !"); @@ -204,7 +237,9 @@ public void setViewPager(ViewPager vp, String[] titles) { notifyDataSetChanged(); } - /** 关联ViewPager,用于连适配器都不想自己实例化的情况 */ + /** + * 关联ViewPager,用于连适配器都不想自己实例化的情况 + */ public void setViewPager(ViewPager vp, String[] titles, FragmentActivity fa, ArrayList fragments) { if (vp == null) { throw new IllegalStateException("ViewPager can not be NULL !"); @@ -222,12 +257,16 @@ public void setViewPager(ViewPager vp, String[] titles, FragmentActivity fa, Arr notifyDataSetChanged(); } - /** 更新数据 */ + /** + * 更新数据 + */ public void notifyDataSetChanged() { mTabsContainer.removeAllViews(); this.mTabCount = mTitles == null ? mViewPager.getAdapter().getCount() : mTitles.size(); View tabView; + mTabState = new ArrayList<>(); for (int i = 0; i < mTabCount; i++) { + mTabState.add(false); tabView = View.inflate(mContext, R.layout.layout_tab, null); CharSequence pageTitle = mTitles == null ? mViewPager.getAdapter().getPageTitle(i) : mTitles.get(i); addTab(i, pageTitle.toString(), tabView); @@ -245,11 +284,15 @@ public void addNewTab(String title) { CharSequence pageTitle = mTitles == null ? mViewPager.getAdapter().getPageTitle(mTabCount) : mTitles.get(mTabCount); addTab(mTabCount, pageTitle.toString(), tabView); this.mTabCount = mTitles == null ? mViewPager.getAdapter().getCount() : mTitles.size(); - + if (mTabState != null) { + mTabState.add(false); + } updateTabStyles(); } - /** 创建并添加tab */ + /** + * 创建并添加tab + */ private void addTab(final int position, String title, View tabView) { TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title); if (tv_tab_title != null) { @@ -262,15 +305,14 @@ public void onClick(View v) { int position = mTabsContainer.indexOfChild(v); if (position != -1) { if (mViewPager.getCurrentItem() != position) { + if (mListener != null) { + mListener.onTabSelect(position); + } if (mSnapOnTabClick) { mViewPager.setCurrentItem(position, false); } else { mViewPager.setCurrentItem(position); } - - if (mListener != null) { - mListener.onTabSelect(position); - } } else { if (mListener != null) { mListener.onTabReselect(position); @@ -334,7 +376,9 @@ public void onPageSelected(int position) { public void onPageScrollStateChanged(int state) { } - /** HorizontalScrollView滚到当前tab,并且居中显示 */ + /** + * HorizontalScrollView滚到当前tab,并且居中显示 + */ private void scrollToCurrentTab() { if (mTabCount <= 0) { return; @@ -442,7 +486,35 @@ protected void onDraw(Canvas canvas) { if (isInEditMode() || mTabCount <= 0) { return; } - + if (mTabDefaultDrawable != null) { + int centerY = mHeight / 2; + for (int i = 0; i < mTabCount; i++) { + View tab = mTabsContainer.getChildAt(i); + boolean tabState = mTabState.get(i) && mTabCompleteDrawable != null; + int drawableHeight = tabState ? mTabCompleteDrawable.getIntrinsicHeight() : mTabDefaultDrawable.getIntrinsicHeight(); + int drawableWidth = tabState ? mTabCompleteDrawable.getIntrinsicWidth() : mTabDefaultDrawable.getIntrinsicWidth(); + int top = centerY - drawableHeight / 2; + int bottom = centerY + drawableHeight / 2; + int centerX = tab.getLeft() + (tab.getRight() - tab.getLeft()) / 2 + getPaddingLeft(); + mTabCompleteDrawable.setBounds(centerX - drawableWidth / 2, + top, + centerX + drawableWidth / 2, + bottom); + if (tabState) { + mTabCompleteDrawable.setBounds(centerX - drawableWidth / 2, + top, + centerX + drawableWidth / 2, + bottom); + mTabCompleteDrawable.draw(canvas); + } else { + mTabDefaultDrawable.setBounds(centerX - drawableWidth / 2, + top, + centerX + drawableWidth / 2, + bottom); + mTabDefaultDrawable.draw(canvas); + } + } + } int height = getHeight(); int paddingLeft = getPaddingLeft(); // draw divider @@ -523,6 +595,34 @@ protected void onDraw(Canvas canvas) { } } + /** + * 设置tab完成状态 + * + * @param states + */ + public void setTabStateTabStateComplete(int... states) { + for (int state : states) { + if (state < mTabState.size()) { + mTabState.set(state, true); + } + } + invalidate(); + } + + /** + * 设置tab默认状态 + * + * @param states + */ + public void setTabStateTabStateDefault(int... states) { + for (int state : states) { + if (state < mTabState.size()) { + mTabState.set(state, false); + } + } + invalidate(); + } + //setter and getter public void setCurrentTab(int currentTab) { this.mCurrentTab = currentTab; @@ -799,7 +899,9 @@ public void showDot(int position) { showMsg(position, 0); } - /** 隐藏未读消息 */ + /** + * 隐藏未读消息 + */ public void hideMsg(int position) { if (position >= mTabCount) { position = mTabCount - 1; @@ -812,7 +914,9 @@ public void hideMsg(int position) { } } - /** 设置未读消息偏移,原点为文字的右上角.当控件高度固定,消息提示位置易控制,显示效果佳 */ + /** + * 设置未读消息偏移,原点为文字的右上角.当控件高度固定,消息提示位置易控制,显示效果佳 + */ public void setMsgMargin(int position, float leftPadding, float bottomPadding) { if (position >= mTabCount) { position = mTabCount - 1; @@ -831,7 +935,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/FlycoTabLayout_Lib/src/main/res/values/attrs.xml b/FlycoTabLayout_Lib/src/main/res/values/attrs.xml index b0afdbee..d15ee020 100644 --- a/FlycoTabLayout_Lib/src/main/res/values/attrs.xml +++ b/FlycoTabLayout_Lib/src/main/res/values/attrs.xml @@ -105,7 +105,8 @@ - + + diff --git a/app/build.gradle b/app/build.gradle index f2f86d4d..6b81e257 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.application' - +apply plugin: 'kotlin-android' android { compileSdkVersion 25 - buildToolsVersion "25.0.2" + buildToolsVersion '26.0.2' defaultConfig { applicationId "com.flyco.tablayoutsamples" - minSdkVersion 11 + minSdkVersion 14 targetSdkVersion 25 versionCode 1 versionName "1.0" @@ -17,15 +17,22 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + + lintOptions { + abortOnError false + } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) + //noinspection GradleCompatible compile 'com.android.support:appcompat-v7:25.1.0' -// compile project(':FlycoTabLayout_Lib') + compile project(':FlycoTabLayout_Lib') + + compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" //--->support 3.0+ - compile 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar' +// compile '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/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b9a3f790..0f5c1975 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ - + - + - + + android:screenOrientation="portrait" /> + android:screenOrientation="portrait" /> + android:screenOrientation="portrait" /> + diff --git a/app/src/main/java/com/flyco/tablayoutsamples/entity/Demo.kt b/app/src/main/java/com/flyco/tablayoutsamples/entity/Demo.kt new file mode 100644 index 00000000..501e18b5 --- /dev/null +++ b/app/src/main/java/com/flyco/tablayoutsamples/entity/Demo.kt @@ -0,0 +1,3 @@ +package com.flyco.tablayoutsamples.entity + +class Demo diff --git a/app/src/main/java/com/flyco/tablayoutsamples/ui/SildingActivity.kt b/app/src/main/java/com/flyco/tablayoutsamples/ui/SildingActivity.kt new file mode 100644 index 00000000..a27c8aab --- /dev/null +++ b/app/src/main/java/com/flyco/tablayoutsamples/ui/SildingActivity.kt @@ -0,0 +1,53 @@ +package com.flyco.tablayoutsamples.ui + +import android.os.Build +import android.os.Bundle +import android.support.annotation.RequiresApi +import android.support.v4.app.Fragment +import android.support.v4.app.FragmentManager +import android.support.v4.app.FragmentPagerAdapter +import android.support.v7.app.AppCompatActivity +import com.flyco.tablayout.CommonTabLayout +import com.flyco.tablayout.listener.CustomTabEntity +import com.flyco.tablayoutsamples.R +import com.flyco.tablayoutsamples.entity.TabEntity +import java.util.* + +/** + * Created by zengwendi on 2018/4/26. + */ + +class SildingActivity : AppCompatActivity() { + + private val mFragments = ArrayList() + private var mAdapter: MyPagerAdapter? = null + private val mTitles = arrayOf("自动投标", "散标", "债转") + private val mTabEntities = ArrayList() + + @RequiresApi(Build.VERSION_CODES.JELLY_BEAN) + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_sliding) + val tabEntitys = mTitles.mapTo(destination = ArrayList()) { + TabEntity(it, 0, 0) + } + var tab = findViewById(R.id.tl_6) as CommonTabLayout + tab.setTabData(tabEntitys) + + } + + private inner class MyPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) { + + override fun getCount(): Int { + return mFragments.size + } + + override fun getPageTitle(position: Int): CharSequence { + return mTitles[position] + } + + override fun getItem(position: Int): Fragment { + return mFragments[position] + } + } +} diff --git a/app/src/main/java/com/flyco/tablayoutsamples/ui/SimpleHomeActivity.java b/app/src/main/java/com/flyco/tablayoutsamples/ui/SimpleHomeActivity.java index 087c3e7a..c589ca30 100644 --- a/app/src/main/java/com/flyco/tablayoutsamples/ui/SimpleHomeActivity.java +++ b/app/src/main/java/com/flyco/tablayoutsamples/ui/SimpleHomeActivity.java @@ -11,11 +11,12 @@ import com.flyco.tablayoutsamples.adapter.SimpleHomeAdapter; + public class SimpleHomeActivity extends AppCompatActivity { private Context mContext = this; - private final String[] mItems = {"SlidingTabLayout", "CommonTabLayout", "SegmentTabLayout"}; + private final String[] mItems = {"SlidingTabLayout", "CommonTabLayout", "SegmentTabLayout", "SlidingTabActivity"}; private final Class[] mClasses = {SlidingTabActivity.class, CommonTabActivity.class, - SegmentTabActivity.class}; + SegmentTabActivity.class, SildingActivity.class}; @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/res/drawable/shape_bt_red_fillet.xml b/app/src/main/res/drawable/shape_bt_red_fillet.xml new file mode 100644 index 00000000..90067e99 --- /dev/null +++ b/app/src/main/res/drawable/shape_bt_red_fillet.xml @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/app/src/main/res/drawable/shape_bt_tow_fillet.xml b/app/src/main/res/drawable/shape_bt_tow_fillet.xml new file mode 100644 index 00000000..64ad0aec --- /dev/null +++ b/app/src/main/res/drawable/shape_bt_tow_fillet.xml @@ -0,0 +1,11 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_sliding.xml b/app/src/main/res/layout/activity_sliding.xml new file mode 100644 index 00000000..e5b747ff --- /dev/null +++ b/app/src/main/res/layout/activity_sliding.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_sliding_tab.xml b/app/src/main/res/layout/activity_sliding_tab.xml index 3df558dd..695a1541 100644 --- a/app/src/main/res/layout/activity_sliding_tab.xml +++ b/app/src/main/res/layout/activity_sliding_tab.xml @@ -101,13 +101,22 @@ + tl:tl_indicator_color="#5490F4" + tl:tl_indicator_height="20dp" + tl:tl_indicator_margin_top="10dp" + tl:tl_indicator_style="BLOCK" + tl:tl_indicator_width="20dp" + tl:tl_tab_complete_background="@drawable/shape_bt_red_fillet" + tl:tl_tab_default_background="@drawable/shape_bt_tow_fillet" + tl:tl_tab_width="60dp" + tl:tl_textSelectColor="#ffffff" + tl:tl_textUnselectColor="#ffffff"/> + Date: Tue, 23 Oct 2018 16:00:54 +0800 Subject: [PATCH 3/4] =?UTF-8?q?Merge=20branch=20'master'=20of=20https://gi?= =?UTF-8?q?thub.com/zengwendi/FlycoTabLayout=20=E8=AE=BE=E7=BD=AECommonTab?= =?UTF-8?q?Layout=E9=80=89=E4=B8=AD=E5=AD=97=E4=BD=93=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlycoTabLayout_Lib/build.gradle | 3 +- .../com/flyco/tablayout/CommonTabLayout.java | 61 +++++++++++++++---- .../src/main/res/values/attrs.xml | 1 + app/build.gradle | 10 ++- .../tablayoutsamples/ui/SildingActivity.kt | 3 + app/src/main/res/layout/activity_sliding.xml | 23 +++++-- gradle.properties | 3 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 8 files changed, 78 insertions(+), 28 deletions(-) diff --git a/FlycoTabLayout_Lib/build.gradle b/FlycoTabLayout_Lib/build.gradle index 7a84b1ac..960b8ae4 100644 --- a/FlycoTabLayout_Lib/build.gradle +++ b/FlycoTabLayout_Lib/build.gradle @@ -7,7 +7,6 @@ apply plugin: 'com.novoda.bintray-release'//添加 version = "2.1.2" android { compileSdkVersion 26 - buildToolsVersion "26.0.2" defaultConfig { minSdkVersion 11 @@ -51,7 +50,7 @@ task javadoc(type: Javadoc) { publish { artifactId = 'FlycoTabLayout_Lib' // library的名字 groupId = 'com.vclicai'// 包名 - publishVersion = '1.0.6' // 版本 + publishVersion = '1.1.0' // 版本 website = 'https://github.com/H07000223/FlycoTabLayout' userOrg = 'vclicai' } 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..8100c2f2 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,27 +79,36 @@ 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; private float mTextsize; + private float mTextSelectSize; private int mTextSelectColor; private int mTextUnselectColor; private int mTextBold; private boolean mTextAllCaps; - /** icon */ + /** + * icon + */ private boolean mIconVisible; private int mIconGravity; private float mIconWidth; @@ -102,7 +117,9 @@ public class CommonTabLayout extends FrameLayout implements ValueAnimator.Animat private int mHeight; - /** anim */ + /** + * anim + */ private ValueAnimator mValueAnimator; private OvershootInterpolator mInterpolator = new OvershootInterpolator(1.5f); @@ -172,6 +189,10 @@ private void obtainAttributes(Context context, AttributeSet attrs) { mDividerPadding = ta.getDimension(R.styleable.CommonTabLayout_tl_divider_padding, dp2px(12)); mTextsize = ta.getDimension(R.styleable.CommonTabLayout_tl_textsize, sp2px(13f)); + mTextSelectSize = ta.getDimension(R.styleable.CommonTabLayout_tl_textSelectSize, sp2px(0f)); + if (mTextSelectSize == 0) { + mTextSelectSize = mTextsize; + } mTextSelectColor = ta.getColor(R.styleable.CommonTabLayout_tl_textSelectColor, Color.parseColor("#ffffff")); mTextUnselectColor = ta.getColor(R.styleable.CommonTabLayout_tl_textUnselectColor, Color.parseColor("#AAffffff")); mTextBold = ta.getInt(R.styleable.CommonTabLayout_tl_textBold, TEXT_BOLD_NONE); @@ -201,13 +222,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,7 +255,9 @@ 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()); @@ -270,7 +297,7 @@ private void updateTabStyles() { tabView.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0); TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title); tv_tab_title.setTextColor(i == mCurrentTab ? mTextSelectColor : mTextUnselectColor); - tv_tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextsize); + tv_tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, i == mCurrentTab ? mTextSelectSize : mTextsize); // tv_tab_title.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0); if (mTextAllCaps) { tv_tab_title.setText(tv_tab_title.getText().toString().toUpperCase()); @@ -313,6 +340,7 @@ private void updateTabSelection(int position) { final boolean isSelect = i == position; TextView tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title); tab_title.setTextColor(isSelect ? mTextSelectColor : mTextUnselectColor); + tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, isSelect ? mTextSelectSize : mTextsize); ImageView iv_tab_icon = (ImageView) tabView.findViewById(R.id.iv_tab_icon); CustomTabEntity tabEntity = mTabEntitys.get(i); iv_tab_icon.setImageResource(isSelect ? tabEntity.getTabSelectedIcon() : tabEntity.getTabUnselectedIcon()); @@ -598,6 +626,11 @@ public void setTextsize(float textsize) { updateTabStyles(); } + public void setmTextSelectSize(int textSelectSize) { + this.mTextSelectSize = textSelectSize; + updateTabStyles(); + } + public void setTextSelectColor(int textSelectColor) { this.mTextSelectColor = textSelectColor; updateTabStyles(); @@ -885,7 +918,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/FlycoTabLayout_Lib/src/main/res/values/attrs.xml b/FlycoTabLayout_Lib/src/main/res/values/attrs.xml index d15ee020..d6f07f12 100644 --- a/FlycoTabLayout_Lib/src/main/res/values/attrs.xml +++ b/FlycoTabLayout_Lib/src/main/res/values/attrs.xml @@ -149,6 +149,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 6b81e257..647420fb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,11 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { - compileSdkVersion 25 - buildToolsVersion '26.0.2' - + compileSdkVersion 26 defaultConfig { applicationId "com.flyco.tablayoutsamples" - minSdkVersion 14 - targetSdkVersion 25 + minSdkVersion 15 + targetSdkVersion 26 versionCode 1 versionName "1.0" } @@ -26,7 +24,7 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) //noinspection GradleCompatible - compile 'com.android.support:appcompat-v7:25.1.0' + compile 'com.android.support:appcompat-v7:26.1.0' compile project(':FlycoTabLayout_Lib') compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" diff --git a/app/src/main/java/com/flyco/tablayoutsamples/ui/SildingActivity.kt b/app/src/main/java/com/flyco/tablayoutsamples/ui/SildingActivity.kt index a27c8aab..ffaf8390 100644 --- a/app/src/main/java/com/flyco/tablayoutsamples/ui/SildingActivity.kt +++ b/app/src/main/java/com/flyco/tablayoutsamples/ui/SildingActivity.kt @@ -32,7 +32,10 @@ class SildingActivity : AppCompatActivity() { TabEntity(it, 0, 0) } var tab = findViewById(R.id.tl_6) as CommonTabLayout + var tab7 = findViewById(R.id.tl_7) as CommonTabLayout + tab.setTabData(tabEntitys) + tab7.setTabData(tabEntitys) } diff --git a/app/src/main/res/layout/activity_sliding.xml b/app/src/main/res/layout/activity_sliding.xml index e5b747ff..84ad1a97 100644 --- a/app/src/main/res/layout/activity_sliding.xml +++ b/app/src/main/res/layout/activity_sliding.xml @@ -1,9 +1,9 @@ + xmlns:tl="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + tl:tl_textsize="17sp" /> + + \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 1d3591c8..4453f5a6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,4 +15,5 @@ # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true \ No newline at end of file +# org.gradle.parallel=true +android.enableAapt2=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f7406480..5822ee34 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -#Sat Oct 10 13:13:42 CST 2015 +#Tue Oct 23 13:47:29 CST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME From bbda25005e59fd71955547953104e11c094f8c59 Mon Sep 17 00:00:00 2001 From: goat Date: Wed, 7 Nov 2018 09:49:11 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E8=AE=BE=E7=BD=AECommonTabLayout=E9=80=89?= =?UTF-8?q?=E4=B8=AD=E5=AD=97=E4=BD=93=E5=8A=A0=E7=B2=97=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlycoTabLayout_Lib/build.gradle | 4 ++-- .../src/main/java/com/flyco/tablayout/CommonTabLayout.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/FlycoTabLayout_Lib/build.gradle b/FlycoTabLayout_Lib/build.gradle index 960b8ae4..b048b5a1 100644 --- a/FlycoTabLayout_Lib/build.gradle +++ b/FlycoTabLayout_Lib/build.gradle @@ -50,7 +50,7 @@ task javadoc(type: Javadoc) { publish { artifactId = 'FlycoTabLayout_Lib' // library的名字 groupId = 'com.vclicai'// 包名 - publishVersion = '1.1.0' // 版本 + publishVersion = '1.1.2' // 版本 website = 'https://github.com/H07000223/FlycoTabLayout' userOrg = 'vclicai' } @@ -60,7 +60,7 @@ publish { //group = "com.flyco.tablayout" // Maven Group ID for the artifact,一般填你唯一的包名 //install { // repositories.mavenInstaller { -// // This generates POM.xml with proper parameters +// // This generate1 POM.xml with proper parameters // pom { // project { // packaging 'aar' 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 8100c2f2..c44b7de7 100644 --- a/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/CommonTabLayout.java +++ b/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/CommonTabLayout.java @@ -307,6 +307,8 @@ private void updateTabStyles() { tv_tab_title.getPaint().setFakeBoldText(true); } else if (mTextBold == TEXT_BOLD_NONE) { tv_tab_title.getPaint().setFakeBoldText(false); + }else if (mTextBold ==TEXT_BOLD_WHEN_SELECT){ + tv_tab_title.getPaint().setFakeBoldText(i == mCurrentTab); } ImageView iv_tab_icon = (ImageView) tabView.findViewById(R.id.iv_tab_icon);