Skip to content

Commit

Permalink
修改TabView布局
Browse files Browse the repository at this point in the history
  • Loading branch information
BzCoder committed May 8, 2019
1 parent 749ef06 commit 17d95e2
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 33 deletions.
13 changes: 7 additions & 6 deletions FlycoTabLayout_Lib/build.gradle
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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' // 项目的主页
Expand Down
3 changes: 3 additions & 0 deletions FlycoTabLayout_Lib/jitpack.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
apply plugin: 'com.github.dcendents.android-maven'

group = 'com.github.BzCoder'
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,19 @@

import java.util.ArrayList;

/** 没有继承HorizontalScrollView不能滑动,对于ViewPager无依赖 */
/**
* 没有继承HorizontalScrollView不能滑动,对于ViewPager无依赖
*/
public class CommonTabLayout extends FrameLayout implements ValueAnimator.AnimatorUpdateListener {
private Context mContext;
private ArrayList<CustomTabEntity> mTabEntitys = new ArrayList<>();
private LinearLayout mTabsContainer;
private int mCurrentTab;
private int mLastTab;
private int mTabCount;
/** 用于绘制显示器 */
/**
* 用于绘制显示器
*/
private Rect mIndicatorRect = new Rect();
private GradientDrawable mIndicatorDrawable = new GradientDrawable();

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -201,13 +217,17 @@ public void setTabData(ArrayList<CustomTabEntity> tabEntitys) {
notifyDataSetChanged();
}

/** 关联数据支持同时切换fragments */
/**
* 关联数据支持同时切换fragments
*/
public void setTabData(ArrayList<CustomTabEntity> tabEntitys, FragmentActivity fa, int containerViewId, ArrayList<Fragment> fragments) {
mFragmentChangeManager = new FragmentChangeManager(fa.getSupportFragmentManager(), containerViewId, fragments);
setTabData(tabEntitys);
}

/** 更新数据 */
/**
* 更新数据
*/
public void notifyDataSetChanged() {
mTabsContainer.removeAllViews();
this.mTabCount = mTabEntitys.size();
Expand All @@ -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());

Expand Down Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class CommonTabActivity extends AppCompatActivity {
private ArrayList<Fragment> mFragments = new ArrayList<>();
private ArrayList<Fragment> 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};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public class SegmentTabActivity extends AppCompatActivity {
private ArrayList<Fragment> mFragments = new ArrayList<>();
private ArrayList<Fragment> 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;

Expand Down
10 changes: 9 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
// }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 17d95e2

Please sign in to comment.