├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── jiang
│ │ └── android
│ │ └── scalabletabindicator
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── jiang
│ │ │ └── android
│ │ │ └── scalabletabindicator
│ │ │ ├── MainActivity.java
│ │ │ ├── SimpleFragment.java
│ │ │ ├── TabView1.java
│ │ │ ├── TabView2.java
│ │ │ ├── TabView3.java
│ │ │ └── Utils.java
│ └── res
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── fragment_main.xml
│ │ ├── tab1_layout.xml
│ │ ├── tab2_layout.xml
│ │ └── tab3_layout.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ ├── tab1.png
│ │ └── tab2.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── jiang
│ └── android
│ └── scalabletabindicator
│ └── ExampleUnitTest.java
├── art
└── 7.gif
├── build.gradle
├── gradle.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── jiang
│ │ └── android
│ │ └── scalabletabindicator
│ │ └── library
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── jiang
│ │ │ └── android
│ │ │ └── scalabletabindicator
│ │ │ └── library
│ │ │ ├── ScalableTabIndicator.java
│ │ │ └── Tab.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── jiang
│ └── android
│ └── scalabletabindicator
│ └── library
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ScalableTabIndicator
2 | ### 可定制的Indicator,结合ViewPager使用,当然不通过ViewPager也可以用
3 | [  ](https://bintray.com/yuesong/maven/ScalableTabIndicator/_latestVersion)
4 |
5 |
6 |
7 | 
8 |
9 |
10 | ### 导入
11 | gradle
12 | ```
13 | compile 'com.jiang.android.scalabletabindicator:library:1.0.5'
14 |
15 | ```
16 |
17 |
18 | Maven
19 | ```
20 |
21 | com.jiang.android.scalabletabindicator
22 | library
23 | 1.0.5
24 | pom
25 |
26 | ```
27 |
28 | ### 用法
29 |
30 | >* 导入项目
31 |
32 | ```
33 | compile 'com.jiang.android.scalabletabindicator:library:1.0.5'
34 |
35 | ```
36 |
37 | >* 在layout中加入
38 |
39 | ```xml
40 |
45 | ```
46 |
47 | >* 在代码中加入
48 |
49 | ```java
50 | mScalableTabIndicator = (ScalableTabIndicator) this.findViewById(R.id.tabindicator);
51 | /*可要可不要,如果你用到了ViewPager那就要,如果没用到ViewPager那就需要初始化的时候调用mScalableTabIndicator.setCurrentIte m(0);然后mScalableTabIndicator需要实现OnItemClickListener接口 */
52 | mScalableTabIndicator.setViewPager(pager);
53 | mScalableTabIndicator.addTab(//TODO...);
54 | //没有ViewPager的情况下使用下面这两句
55 | mScalableTabIndicator.setOnClickListener(new ScalableTabIndicator.OnItemClickListener() {
56 | @Override
57 | public void onClick(int position) {
58 | }
59 | });
60 | mScalableTabIndicator.setCurrentItem(0);
61 |
62 |
63 | ```
64 |
65 | >* 最关键的一步,新建类继承Tab类,并重写相关的方法,在demo中有TabView1,TabView2和TabView3,3个例子。
66 |
67 | ```java
68 | /**
69 | * 当前被选中
70 | */
71 | public abstract void actived();
72 |
73 | /**
74 | * 当前没有被选中
75 | */
76 | public abstract void dismissed();
77 | /**
78 | * 获取view
79 | *
80 | * @return
81 | */
82 | public abstract View getView();
83 |
84 | ```
85 | >* 注意: 要想知道viewpager回调的进度,可以通过
86 |
87 | ```java
88 | mScalableTabIndicator.setChangeListener(new ScalableTabIndicator.ChangeListener() {
89 | @Override
90 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
91 | }
92 | @Override
93 | public void onPageSelected(int position) {
94 | }
95 | @Override
96 | public void onPageScrollStateChanged(int state) {
97 |
98 | }
99 | });
100 | ```
101 |
102 | 或者重写Tab类中的
103 |
104 | ```java
105 | /**
106 | * 如若需要对tab的item元素进行相关操作,可重写这个方法
107 | *
108 | * @param positionOffset
109 | * @param positionOffsetPixels
110 | */
111 | public void onPageScrolled(float positionOffset, int positionOffsetPixels) {
112 | }
113 | ```
114 |
115 | ###作者
116 | >* New_Tab -
117 |
118 | ###推荐
119 |
120 | >* 收集Android你不知道的那些小技巧:https://github.com/jiang111/awesome-android-tips
121 |
122 | >* 收集Android studio 常用的插件,请看这里:https://github.com/jiang111/awesome-androidstudio-plugins
123 |
124 | >* 收集程序员必备的那些Chrome插件: https://github.com/jiang111/chrome-plugin-recommand
125 |
126 | >* 通过RecyclerView实现的联系人: https://github.com/jiang111/IndexRecyclerView
127 |
128 | >* 用于学习RxJava操作符的APP: https://github.com/jiang111/RxJavaApp
129 |
130 | >* 展示注册进度的view: https://github.com/jiang111/ProgressView
131 |
132 | >* 可定制的ViewPagerIndicator: https://github.com/jiang111/ScalableTabIndicator
133 |
134 | >* 通过viewpager的滑动来对fragment内的元素进行动画操作: https://github.com/jiang111/ViewPagerTransformer
135 |
136 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.jiang.android.scalabletabindicator"
9 | minSdkVersion 15
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.3.0'
26 | compile 'com.jiang.android.viewpagertransformer:transformer:1.0.1'
27 | compile project(':library')
28 | }
29 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/jiang/androidsdk/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/jiang/android/scalabletabindicator/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.jiang.android.scalabletabindicator;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jiang/android/scalabletabindicator/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.jiang.android.scalabletabindicator;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.support.v4.app.FragmentManager;
6 | import android.support.v4.app.FragmentStatePagerAdapter;
7 | import android.support.v4.view.ViewPager;
8 | import android.support.v7.app.AppCompatActivity;
9 |
10 | import com.jiang.android.scalabletabindicator.library.ScalableTabIndicator;
11 | import com.jiang.android.transformer.transformer.RotateTransformer;
12 |
13 | public class MainActivity extends AppCompatActivity {
14 |
15 |
16 | private ScalableTabIndicator mScalableTabIndicator;
17 | private ViewPager mPager;
18 | private ViewPagerAdapter mAdapter;
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_main);
24 | mScalableTabIndicator = (ScalableTabIndicator) this.findViewById(R.id.tabindicator);
25 | mPager = (ViewPager) this.findViewById(R.id.pager);
26 | mScalableTabIndicator.setScrollable(true);
27 | TabView3 tabView3 = new TabView3(this);
28 | tabView3.setText("语文");
29 | mScalableTabIndicator.addTab(tabView3);
30 | TabView3 tabView32 = new TabView3(this);
31 | tabView32.setText("数学活动");
32 | mScalableTabIndicator.addTab(tabView32);
33 | TabView3 tabView33 = new TabView3(this);
34 | tabView33.setText("英语");
35 | mScalableTabIndicator.addTab(tabView33);
36 | TabView3 tabView34 = new TabView3(this);
37 | tabView34.setText("政治活动");
38 | mScalableTabIndicator.addTab(tabView34);
39 | TabView3 tabView35 = new TabView3(this);
40 | tabView35.setText("地理");
41 | mScalableTabIndicator.addTab(tabView35);
42 | TabView3 tabView36 = new TabView3(this);
43 | tabView36.setText("生物活动");
44 | mScalableTabIndicator.addTab(tabView36);
45 | TabView3 tabView37 = new TabView3(this);
46 | tabView37.setText("体育");
47 | mScalableTabIndicator.addTab(tabView37);
48 |
49 | TabView3 tabView38 = new TabView3(this);
50 | tabView38.setText("体育活动");
51 | mScalableTabIndicator.addTab(tabView38);
52 |
53 | TabView3 tabView39 = new TabView3(this);
54 | tabView39.setText("体育");
55 | mScalableTabIndicator.addTab(tabView39);
56 |
57 | TabView3 tabView40 = new TabView3(this);
58 | tabView40.setText("体育活动活动");
59 | mScalableTabIndicator.addTab(tabView40);
60 |
61 | TabView3 tabView41 = new TabView3(this);
62 | tabView41.setText("体育");
63 | mScalableTabIndicator.addTab(tabView41);
64 |
65 | mAdapter = new ViewPagerAdapter(getSupportFragmentManager());
66 | mPager.setPageTransformer(true, new RotateTransformer());
67 | mPager.setAdapter(mAdapter);
68 | mScalableTabIndicator.setViewPager(mPager);
69 |
70 | }
71 |
72 | private class ViewPagerAdapter extends FragmentStatePagerAdapter {
73 |
74 | public ViewPagerAdapter(FragmentManager fm) {
75 | super(fm);
76 |
77 | }
78 |
79 | public Fragment getItem(int num) {
80 | return SimpleFragment.newInstance(num + "", num);
81 | }
82 |
83 | @Override
84 | public int getCount() {
85 | return 11;
86 | }
87 |
88 | @Override
89 | public CharSequence getPageTitle(int position) {
90 | return " " + position;
91 | }
92 |
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jiang/android/scalabletabindicator/SimpleFragment.java:
--------------------------------------------------------------------------------
1 | /**
2 | * created by jiang, 16/2/28
3 | * Copyright (c) 2016, jyuesong@gmail.com All Rights Reserved.
4 | * * # #
5 | * # _oo0oo_ #
6 | * # o8888888o #
7 | * # 88" . "88 #
8 | * # (| -_- |) #
9 | * # 0\ = /0 #
10 | * # ___/`---'\___ #
11 | * # .' \\| |# '. #
12 | * # / \\||| : |||# \ #
13 | * # / _||||| -:- |||||- \ #
14 | * # | | \\\ - #/ | | #
15 | * # | \_| ''\---/'' |_/ | #
16 | * # \ .-\__ '-' ___/-. / #
17 | * # ___'. .' /--.--\ `. .'___ #
18 | * # ."" '< `.___\_<|>_/___.' >' "". #
19 | * # | | : `- \`.;`\ _ /`;.`/ - ` : | | #
20 | * # \ \ `_. \_ __\ /__ _/ .-` / / #
21 | * # =====`-.____`.___ \_____/___.-`___.-'===== #
22 | * # `=---=' #
23 | * # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
24 | * # #
25 | * # 佛祖保佑 永无BUG #
26 | * # #
27 | */
28 |
29 | package com.jiang.android.scalabletabindicator;
30 |
31 | import android.os.Bundle;
32 | import android.support.annotation.Nullable;
33 | import android.support.v4.app.Fragment;
34 | import android.view.LayoutInflater;
35 | import android.view.View;
36 | import android.view.ViewGroup;
37 | import android.widget.RelativeLayout;
38 | import android.widget.TextView;
39 |
40 | /**
41 | * Created by jiang on 16/2/28.
42 | */
43 |
44 | public class SimpleFragment extends Fragment {
45 |
46 | public static final String BUNDLE_TITLE = "title";
47 | private String mTitle = "DefaultValue";
48 | private RelativeLayout mBG;
49 | private TextView mTitle1;
50 | private int mPosition;
51 |
52 | @Override
53 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
54 | Bundle savedInstanceState) {
55 | Bundle arguments = getArguments();
56 | if (arguments != null) {
57 | mTitle = arguments.getString(BUNDLE_TITLE);
58 | mPosition = arguments.getInt("position");
59 | }
60 |
61 | View root = inflater.inflate(R.layout.fragment_main, null);
62 | mBG = (RelativeLayout) root.findViewById(R.id.fragment_bg);
63 | mTitle1 = (TextView) root.findViewById(R.id.fragment_title);
64 | return root;
65 |
66 | }
67 |
68 | @Override
69 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
70 | super.onActivityCreated(savedInstanceState);
71 | mTitle1.setText(mTitle);
72 | int position = mPosition % 4;
73 | switch (position) {
74 | case 0:
75 | mBG.setBackgroundColor(getResources().getColor(R.color.colorAccent1));
76 | break;
77 | case 1:
78 | mBG.setBackgroundColor(getResources().getColor(R.color.colorAccent2));
79 | break;
80 | case 2:
81 | mBG.setBackgroundColor(getResources().getColor(R.color.colorAccent3));
82 | break;
83 | case 3:
84 | mBG.setBackgroundColor(getResources().getColor(R.color.colorAccent4));
85 | break;
86 | case 4:
87 | mBG.setBackgroundColor(getResources().getColor(R.color.colorAccent5));
88 | break;
89 |
90 | }
91 |
92 | }
93 |
94 | public static SimpleFragment newInstance(String title, int position) {
95 | Bundle bundle = new Bundle();
96 | bundle.putString(BUNDLE_TITLE, title);
97 | bundle.putInt("position", position);
98 | SimpleFragment fragment = new SimpleFragment();
99 |
100 | fragment.setArguments(bundle);
101 |
102 | return fragment;
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jiang/android/scalabletabindicator/TabView1.java:
--------------------------------------------------------------------------------
1 | /**
2 | * created by jiang, 16/5/9
3 | * Copyright (c) 2016, jyuesong@gmail.com All Rights Reserved.
4 | * * # #
5 | * # _oo0oo_ #
6 | * # o8888888o #
7 | * # 88" . "88 #
8 | * # (| -_- |) #
9 | * # 0\ = /0 #
10 | * # ___/`---'\___ #
11 | * # .' \\| |# '. #
12 | * # / \\||| : |||# \ #
13 | * # / _||||| -:- |||||- \ #
14 | * # | | \\\ - #/ | | #
15 | * # | \_| ''\---/'' |_/ | #
16 | * # \ .-\__ '-' ___/-. / #
17 | * # ___'. .' /--.--\ `. .'___ #
18 | * # ."" '< `.___\_<|>_/___.' >' "". #
19 | * # | | : `- \`.;`\ _ /`;.`/ - ` : | | #
20 | * # \ \ `_. \_ __\ /__ _/ .-` / / #
21 | * # =====`-.____`.___ \_____/___.-`___.-'===== #
22 | * # `=---=' #
23 | * # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
24 | * # #
25 | * # 佛祖保佑 永无BUG #
26 | * # #
27 | */
28 |
29 | package com.jiang.android.scalabletabindicator;
30 |
31 | import android.content.Context;
32 | import android.view.LayoutInflater;
33 | import android.view.View;
34 | import android.widget.LinearLayout;
35 | import android.widget.TextView;
36 |
37 | import com.jiang.android.scalabletabindicator.library.Tab;
38 |
39 | /**
40 | * Created by jiang on 16/5/9.
41 | */
42 | public class TabView1 extends Tab {
43 |
44 | private final LinearLayout mRootView;
45 | private final TextView mTab1Tv;
46 |
47 | public TabView1(Context context) {
48 | mRootView = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.tab1_layout, null);
49 | mTab1Tv = (TextView) mRootView.findViewById(R.id.tab1_tv);
50 | mRootView.setClickable(true);
51 | mRootView.setOnClickListener(this);
52 | }
53 |
54 | public void setText(String title) {
55 | mTab1Tv.setText(title);
56 | }
57 |
58 | @Override
59 | public void actived() {
60 | mTab1Tv.setTextColor(mRootView.getResources().getColor(R.color.colorAccent));
61 |
62 | }
63 |
64 | @Override
65 | public void dismissed() {
66 | mTab1Tv.setTextColor(mRootView.getResources().getColor(R.color.black));
67 |
68 | }
69 |
70 |
71 | @Override
72 | public View getView() {
73 | return mRootView;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jiang/android/scalabletabindicator/TabView2.java:
--------------------------------------------------------------------------------
1 | /**
2 | * created by jiang, 16/5/9
3 | * Copyright (c) 2016, jyuesong@gmail.com All Rights Reserved.
4 | * * # #
5 | * # _oo0oo_ #
6 | * # o8888888o #
7 | * # 88" . "88 #
8 | * # (| -_- |) #
9 | * # 0\ = /0 #
10 | * # ___/`---'\___ #
11 | * # .' \\| |# '. #
12 | * # / \\||| : |||# \ #
13 | * # / _||||| -:- |||||- \ #
14 | * # | | \\\ - #/ | | #
15 | * # | \_| ''\---/'' |_/ | #
16 | * # \ .-\__ '-' ___/-. / #
17 | * # ___'. .' /--.--\ `. .'___ #
18 | * # ."" '< `.___\_<|>_/___.' >' "". #
19 | * # | | : `- \`.;`\ _ /`;.`/ - ` : | | #
20 | * # \ \ `_. \_ __\ /__ _/ .-` / / #
21 | * # =====`-.____`.___ \_____/___.-`___.-'===== #
22 | * # `=---=' #
23 | * # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
24 | * # #
25 | * # 佛祖保佑 永无BUG #
26 | * # #
27 | */
28 |
29 | package com.jiang.android.scalabletabindicator;
30 |
31 | import android.content.Context;
32 | import android.view.LayoutInflater;
33 | import android.view.View;
34 | import android.widget.LinearLayout;
35 | import android.widget.TextView;
36 |
37 | import com.jiang.android.scalabletabindicator.library.Tab;
38 |
39 | /**
40 | * Created by jiang on 16/5/9.
41 | */
42 | public class TabView2 extends Tab {
43 |
44 | private final LinearLayout mRootView;
45 | private final TextView mTab2Tv;
46 |
47 | public TabView2(Context context) {
48 | mRootView = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.tab2_layout, null);
49 | mTab2Tv = (TextView) mRootView.findViewById(R.id.tab2_tv);
50 | mRootView.setClickable(true);
51 | mRootView.setOnClickListener(this);
52 | }
53 |
54 | public void setText(String title) {
55 | mTab2Tv.setText(title);
56 | }
57 |
58 | @Override
59 | public void actived() {
60 | mTab2Tv.setTextColor(mRootView.getResources().getColor(R.color.colorAccent));
61 |
62 | }
63 |
64 | @Override
65 | public void dismissed() {
66 | mTab2Tv.setTextColor(mRootView.getResources().getColor(R.color.black));
67 |
68 | }
69 |
70 |
71 | @Override
72 | public View getView() {
73 | return mRootView;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jiang/android/scalabletabindicator/TabView3.java:
--------------------------------------------------------------------------------
1 | /**
2 | * created by jiang, 16/5/12
3 | * Copyright (c) 2016, jyuesong@gmail.com All Rights Reserved.
4 | * * # #
5 | * # _oo0oo_ #
6 | * # o8888888o #
7 | * # 88" . "88 #
8 | * # (| -_- |) #
9 | * # 0\ = /0 #
10 | * # ___/`---'\___ #
11 | * # .' \\| |# '. #
12 | * # / \\||| : |||# \ #
13 | * # / _||||| -:- |||||- \ #
14 | * # | | \\\ - #/ | | #
15 | * # | \_| ''\---/'' |_/ | #
16 | * # \ .-\__ '-' ___/-. / #
17 | * # ___'. .' /--.--\ `. .'___ #
18 | * # ."" '< `.___\_<|>_/___.' >' "". #
19 | * # | | : `- \`.;`\ _ /`;.`/ - ` : | | #
20 | * # \ \ `_. \_ __\ /__ _/ .-` / / #
21 | * # =====`-.____`.___ \_____/___.-`___.-'===== #
22 | * # `=---=' #
23 | * # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
24 | * # #
25 | * # 佛祖保佑 永无BUG #
26 | * # #
27 | */
28 |
29 | package com.jiang.android.scalabletabindicator;
30 |
31 | import android.content.Context;
32 | import android.view.LayoutInflater;
33 | import android.view.View;
34 | import android.widget.LinearLayout;
35 | import android.widget.TextView;
36 |
37 | import com.jiang.android.scalabletabindicator.library.Tab;
38 |
39 | /**
40 | * Created by jiang on 16/5/12.
41 | */
42 | public class TabView3 extends Tab {
43 |
44 |
45 | private Context mContext;
46 | private final LinearLayout mRoot;
47 | private final TextView mTab3;
48 | private final View mTab3Line;
49 |
50 | public TabView3(Context context) {
51 | this.mContext = context;
52 | mRoot = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.tab3_layout, null);
53 | mTab3 = (TextView) mRoot.findViewById(R.id.tab3_tv);
54 | mTab3Line = mRoot.findViewById(R.id.tab3_tv_line);
55 | mRoot.setClickable(true);
56 | mRoot.setOnClickListener(this);
57 | }
58 |
59 | public void setText(String text) {
60 | mTab3.setText(text);
61 | }
62 |
63 | @Override
64 | public void actived() {
65 | mTab3.setTextColor(mContext.getResources().getColor(R.color.colorAccent));
66 | mTab3.setTextSize(18);
67 | mTab3Line.setVisibility(View.VISIBLE);
68 | }
69 |
70 | @Override
71 | public void dismissed() {
72 | mTab3.setTextColor(mContext.getResources().getColor(R.color.black));
73 | mTab3.setTextSize(14);
74 | mTab3Line.setVisibility(View.GONE);
75 |
76 | }
77 |
78 |
79 | @Override
80 | public View getView() {
81 | return mRoot;
82 | }
83 |
84 | @Override
85 | public void onPageScrolled(float positionOffset, int positionOffsetPixels) {
86 | super.onPageScrolled(positionOffset, positionOffsetPixels);
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jiang/android/scalabletabindicator/Utils.java:
--------------------------------------------------------------------------------
1 | package com.jiang.android.scalabletabindicator;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Created by guxin on 16/2/2.
7 | */
8 | public class Utils {
9 | /**
10 | * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
11 | *
12 | * @param context
13 | * @param dpValue
14 | * @return
15 | */
16 | public static int dip2px(Context context, float dpValue) {
17 | final float scale = context.getResources().getDisplayMetrics().density;
18 | return (int) (dpValue * scale + 0.5f);
19 | }
20 |
21 |
22 | /**
23 | * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
24 | */
25 | public static int px2dip(Context context, float pxValue) {
26 | final float scale = context.getResources().getDisplayMetrics().density;
27 | return (int) (pxValue / scale + 0.5f);
28 | }
29 |
30 | /**
31 | * 将sp值转换为px值,保证文字大小不变
32 | *
33 | * @param spValue (DisplayMetrics类中属性scaledDensity)
34 | * @return
35 | */
36 | public static int sp2px(Context context, float spValue) {
37 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
38 | return (int) (spValue * fontScale + 0.5f);
39 | }
40 |
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/tab1_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/tab2_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/tab3_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiang111/ScalableTabIndicator/326b7c6910f9471ea61806282964976baa1e237e/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiang111/ScalableTabIndicator/326b7c6910f9471ea61806282964976baa1e237e/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiang111/ScalableTabIndicator/326b7c6910f9471ea61806282964976baa1e237e/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiang111/ScalableTabIndicator/326b7c6910f9471ea61806282964976baa1e237e/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/tab1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiang111/ScalableTabIndicator/326b7c6910f9471ea61806282964976baa1e237e/app/src/main/res/mipmap-xxhdpi/tab1.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/tab2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiang111/ScalableTabIndicator/326b7c6910f9471ea61806282964976baa1e237e/app/src/main/res/mipmap-xxhdpi/tab2.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiang111/ScalableTabIndicator/326b7c6910f9471ea61806282964976baa1e237e/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #ffffff
7 | #000000
8 | #0000f1
9 | #004081
10 | #00FF00
11 | #FFFF81
12 | #FF40FF
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ScalableTabIndicator
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/jiang/android/scalabletabindicator/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.jiang.android.scalabletabindicator;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/art/7.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiang111/ScalableTabIndicator/326b7c6910f9471ea61806282964976baa1e237e/art/7.gif
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.5.0'
9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 | plugins {
16 | id "com.jfrog.bintray" version "1.6"
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | jcenter()
22 | }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: 'com.jfrog.bintray'
4 | // This is the library version used when deploying the artifact
5 | version = "1.0.6"
6 | android {
7 | compileSdkVersion 23
8 | buildToolsVersion "23.0.3"
9 | resourcePrefix "jiang_"
10 | defaultConfig {
11 | minSdkVersion 15
12 | targetSdkVersion 23
13 | versionCode 7
14 | versionName "1.6"
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | testCompile 'junit:junit:4.12'
27 | compile 'com.android.support:appcompat-v7:23.3.0'
28 | }
29 |
30 |
31 | def siteUrl = 'https://github.com/jiang111/ScalableTabIndicator' // 项目的主页
32 | def gitUrl = 'https://github.com/jiang111/ScalableTabIndicator.git' // Git仓库的url
33 | group = "com.jiang.android.scalabletabindicator" // Maven Group ID for the artifact,一般填你唯一的包名
34 | install {
35 | repositories.mavenInstaller {
36 | // This generates POM.xml with proper parameters
37 | pom {
38 | project {
39 | packaging 'aar'
40 | // Add your description here
41 | name 'Android ScalableTabIndicator library' //项目描述
42 | url siteUrl
43 | // Set your license
44 | licenses {
45 | license {
46 | name 'The Apache Software License, Version 2.0'
47 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
48 | }
49 | }
50 | developers {
51 | developer {
52 | id 'jiangyuesong' //填写的一些基本信息
53 | name 'jiangyuesong'
54 | email 'jyuesong@gmail.com'
55 | }
56 | }
57 | scm {
58 | connection gitUrl
59 | developerConnection gitUrl
60 | url siteUrl
61 | }
62 | }
63 | }
64 | }
65 | }
66 | task sourcesJar(type: Jar) {
67 | from android.sourceSets.main.java.srcDirs
68 | classifier = 'sources'
69 | }
70 |
71 | artifacts {
72 | archives sourcesJar
73 | }
74 | Properties properties = new Properties()
75 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
76 | bintray {
77 | user = properties.getProperty("bintray.user")
78 | key = properties.getProperty("bintray.apikey")
79 | configurations = ['archives']
80 | pkg {
81 | repo = "maven"
82 | name = "ScalableTabIndicator" //发布到JCenter上的项目名字
83 | websiteUrl = siteUrl
84 | vcsUrl = gitUrl
85 | licenses = ["Apache-2.0"]
86 | publish = true
87 |
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/jiang/androidsdk/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/jiang/android/scalabletabindicator/library/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.jiang.android.scalabletabindicator.library;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/library/src/main/java/com/jiang/android/scalabletabindicator/library/ScalableTabIndicator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * created by jiang, 16/5/9
3 | * Copyright (c) 2016, jyuesong@gmail.com All Rights Reserved.
4 | * * # #
5 | * # _oo0oo_ #
6 | * # o8888888o #
7 | * # 88" . "88 #
8 | * # (| -_- |) #
9 | * # 0\ = /0 #
10 | * # ___/`---'\___ #
11 | * # .' \\| |# '. #
12 | * # / \\||| : |||# \ #
13 | * # / _||||| -:- |||||- \ #
14 | * # | | \\\ - #/ | | #
15 | * # | \_| ''\---/'' |_/ | #
16 | * # \ .-\__ '-' ___/-. / #
17 | * # ___'. .' /--.--\ `. .'___ #
18 | * # ."" '< `.___\_<|>_/___.' >' "". #
19 | * # | | : `- \`.;`\ _ /`;.`/ - ` : | | #
20 | * # \ \ `_. \_ __\ /__ _/ .-` / / #
21 | * # =====`-.____`.___ \_____/___.-`___.-'===== #
22 | * # `=---=' #
23 | * # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
24 | * # #
25 | * # 佛祖保佑 永无BUG #
26 | * # #
27 | */
28 |
29 | package com.jiang.android.scalabletabindicator.library;
30 |
31 | import android.content.Context;
32 | import android.support.v4.view.ViewPager;
33 | import android.util.AttributeSet;
34 | import android.widget.HorizontalScrollView;
35 | import android.widget.LinearLayout;
36 | import android.widget.RelativeLayout;
37 |
38 | import java.util.LinkedList;
39 | import java.util.List;
40 |
41 | /**
42 | * Created by jiang on 16/5/9.
43 | */
44 | public class ScalableTabIndicator extends RelativeLayout implements ViewPager.OnPageChangeListener {
45 |
46 | private static final String TAG = "ScalableTabIndicator";
47 |
48 | /**
49 | * tabs的数量
50 | */
51 | private List tabs;
52 | /**
53 | * 水平滚动的控件
54 | */
55 | private HorizontalScrollView mScrollView;
56 | private LinearLayout mLinearLayout;
57 | /**
58 | * 可滚动性,默认为true
59 | */
60 | private boolean scrollable = true;
61 | /**
62 | * 当前tab是否被选中
63 | */
64 | private int tabSelected;
65 | /**
66 | * viewpager
67 | */
68 | private ViewPager mViewPager;
69 | /**
70 | * 监听viewpager的滚动状态
71 | */
72 | private ChangeListener changeListener;
73 |
74 | /**
75 | * 当前的item被点击了
76 | */
77 | private OnItemClickListener mOnClickListener;
78 |
79 |
80 | public ScalableTabIndicator(Context context) {
81 | this(context, null);
82 | }
83 |
84 | public ScalableTabIndicator(Context context, AttributeSet attrs) {
85 | this(context, attrs, 0);
86 | }
87 |
88 | public ScalableTabIndicator(Context context, AttributeSet attrs, int defStyleAttr) {
89 | super(context, attrs, defStyleAttr);
90 | init(context);
91 | }
92 |
93 |
94 | /**
95 | * 初始化操作
96 | *
97 | * @param context
98 | */
99 | private void init(Context context) {
100 | mScrollView = new HorizontalScrollView(context);
101 | mScrollView.setOverScrollMode(HorizontalScrollView.OVER_SCROLL_NEVER);
102 | mScrollView.setHorizontalScrollBarEnabled(false);
103 | mLinearLayout = new LinearLayout(context);
104 | mScrollView.addView(mLinearLayout);
105 | tabs = new LinkedList<>();
106 |
107 | }
108 |
109 | @Override
110 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
111 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
112 | int height = MeasureSpec.makeMeasureSpec(getMeasuredHeight() - getPaddingBottom() - getPaddingTop(), MeasureSpec.EXACTLY);
113 | for (int i = 0; i < tabs.size(); i++) {
114 | tabs.get(i).getView().measure(MeasureSpec.UNSPECIFIED, height);
115 | }
116 | }
117 |
118 | /**
119 | * 添加一个view到tab中
120 | *
121 | * @param tab
122 | */
123 | public void addTab(Tab tab) {
124 | tabs.add(tab);
125 | tab.setPosition(tabs.size() - 1);
126 | tab.setScalableTabIndicator(this);
127 | }
128 |
129 | /**
130 | * 进行添加
131 | */
132 | public void notifyDataSetChanged() {
133 | super.removeAllViews();
134 | mLinearLayout.removeAllViews();
135 |
136 | if (scrollable) {
137 | if (!needScrollable()) {
138 | scrollable = false;
139 | }
140 | }
141 | if (!scrollable) {
142 | int tabWidth = this.getWidth() / tabs.size();
143 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(tabWidth, HorizontalScrollView.LayoutParams.MATCH_PARENT);
144 | for (Tab t : tabs) {
145 | mLinearLayout.addView(t.getView(), params);
146 | }
147 | } else {
148 | for (Tab tab : tabs) {
149 | LinearLayout.LayoutParams params;
150 | params = new LinearLayout.LayoutParams(HorizontalScrollView.LayoutParams.WRAP_CONTENT, HorizontalScrollView.LayoutParams.MATCH_PARENT);
151 | mLinearLayout.addView(tab.getView(), params);
152 | }
153 |
154 | }
155 |
156 | RelativeLayout.LayoutParams paramsScroll = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
157 | this.addView(mScrollView, paramsScroll);
158 | this.setSelectedNavigationItem(tabSelected);
159 |
160 | }
161 |
162 | /**
163 | * 判断需不需要进行滚动
164 | *
165 | * @return
166 | */
167 | private boolean needScrollable() {
168 |
169 | int width = 0;
170 | for (int i = 0; i < tabs.size(); i++) {
171 | width += tabs.get(i).getView().getMeasuredWidth();
172 | }
173 | return width > this.getMeasuredWidth() ? true : false;
174 | }
175 |
176 | private void scrollTo(int position) {
177 | int totalWidth = 0;
178 | for (int i = 0; i < position; i++) {
179 | int width = 0;
180 | if (scrollable) {
181 | width = tabs.get(i).getView().getMeasuredWidth();
182 | } else {
183 | width = this.getWidth() / tabs.size();
184 |
185 | }
186 | totalWidth += width;
187 | }
188 | final int finalTotalWidth = totalWidth;
189 | mScrollView.smoothScrollTo(finalTotalWidth, 0);
190 |
191 | }
192 |
193 | @Override
194 | public void removeAllViews() {
195 | for (int i = 0; i < tabs.size(); i++) {
196 | tabs.remove(i);
197 | }
198 | mLinearLayout.removeAllViews();
199 | super.removeAllViews();
200 | }
201 |
202 | public Tab getCurrentTab() {
203 | for (int i = 0; i < tabs.size(); i++) {
204 | if (tabs.get(i).isChecked()) {
205 | return tabs.get(i);
206 | }
207 | }
208 | return null;
209 | }
210 |
211 | public void setCurrentItem(int position) {
212 | if (mViewPager != null) {
213 | mViewPager.setCurrentItem(position);
214 | } else {
215 | setSelectedNavigationItem(position);
216 | if (mOnClickListener != null) {
217 | mOnClickListener.onClick(position);
218 | }
219 |
220 | }
221 | }
222 |
223 | @Override
224 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
225 | super.onSizeChanged(w, h, oldw, oldh);
226 | if (this.getWidth() != 0 && tabs.size() != 0)
227 | notifyDataSetChanged();
228 | }
229 |
230 | public void setSelectedNavigationItem(int position) {
231 | if (position < 0 || position > tabs.size()) {
232 | throw new RuntimeException("Index out bounds");
233 | } else {
234 | for (int i = 0; i < tabs.size(); i++) {
235 | Tab tab = tabs.get(i);
236 | if (i == position) {
237 | tab.active();
238 | } else {
239 | tabs.get(i).dismiss();
240 | }
241 | }
242 | if (scrollable) {
243 | scrollTo(position);
244 | }
245 | tabSelected = position;
246 | }
247 | }
248 |
249 | //***** set get ***//
250 |
251 |
252 | public OnItemClickListener getOnClickListener() {
253 | return mOnClickListener;
254 | }
255 |
256 | public void setOnClickListener(OnItemClickListener onClickListener) {
257 | mOnClickListener = onClickListener;
258 | }
259 |
260 | public ChangeListener getChangeListener() {
261 | return changeListener;
262 | }
263 |
264 | public void setChangeListener(ChangeListener changeListener) {
265 | this.changeListener = changeListener;
266 | }
267 |
268 | public ViewPager getViewPager() {
269 | return mViewPager;
270 | }
271 |
272 | public void setViewPager(ViewPager viewPager) {
273 | mViewPager = viewPager;
274 | mViewPager.setOnPageChangeListener(this);
275 | }
276 |
277 | public boolean isScrollable() {
278 | return scrollable;
279 | }
280 |
281 | public void setScrollable(boolean scrollable) {
282 | this.scrollable = scrollable;
283 | }
284 |
285 | //*****end set get ***//
286 | @Override
287 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
288 |
289 | if (changeListener != null)
290 | changeListener.onPageScrolled(position, positionOffset, positionOffsetPixels);
291 | tabs.get(position).onPageScrolled(positionOffset, positionOffsetPixels);
292 |
293 | }
294 |
295 | @Override
296 | public void onPageSelected(int position) {
297 | setSelectedNavigationItem(position);
298 | if (changeListener != null)
299 | changeListener.onPageSelected(position);
300 | }
301 |
302 | @Override
303 | public void onPageScrollStateChanged(int state) {
304 | if (changeListener != null)
305 | changeListener.onPageScrollStateChanged(state);
306 | }
307 |
308 | /**
309 | * 和viewpager的功能一样
310 | */
311 | public interface ChangeListener {
312 |
313 | void onPageScrolled(int position, float positionOffset, int positionOffsetPixels);
314 |
315 | void onPageSelected(int position);
316 |
317 | void onPageScrollStateChanged(int state);
318 | }
319 |
320 |
321 | public interface OnItemClickListener {
322 |
323 | void onClick(int position);
324 |
325 | }
326 | }
327 |
--------------------------------------------------------------------------------
/library/src/main/java/com/jiang/android/scalabletabindicator/library/Tab.java:
--------------------------------------------------------------------------------
1 | /**
2 | * created by jiang, 16/5/9
3 | * Copyright (c) 2016, jyuesong@gmail.com All Rights Reserved.
4 | * * # #
5 | * # _oo0oo_ #
6 | * # o8888888o #
7 | * # 88" . "88 #
8 | * # (| -_- |) #
9 | * # 0\ = /0 #
10 | * # ___/`---'\___ #
11 | * # .' \\| |# '. #
12 | * # / \\||| : |||# \ #
13 | * # / _||||| -:- |||||- \ #
14 | * # | | \\\ - #/ | | #
15 | * # | \_| ''\---/'' |_/ | #
16 | * # \ .-\__ '-' ___/-. / #
17 | * # ___'. .' /--.--\ `. .'___ #
18 | * # ."" '< `.___\_<|>_/___.' >' "". #
19 | * # | | : `- \`.;`\ _ /`;.`/ - ` : | | #
20 | * # \ \ `_. \_ __\ /__ _/ .-` / / #
21 | * # =====`-.____`.___ \_____/___.-`___.-'===== #
22 | * # `=---=' #
23 | * # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
24 | * # #
25 | * # 佛祖保佑 永无BUG #
26 | * # #
27 | */
28 |
29 | package com.jiang.android.scalabletabindicator.library;
30 |
31 | import android.view.View;
32 |
33 | /**
34 | * Created by jiang on 16/5/9.
35 | */
36 | public abstract class Tab implements View.OnClickListener {
37 |
38 | private static final String TAG = "Tab";
39 |
40 | private boolean checked;
41 | private int position;
42 | private ScalableTabIndicator mScalableTabIndicator;
43 |
44 | public boolean isChecked() {
45 | return checked;
46 | }
47 |
48 | public void active() {
49 | checked = true;
50 | actived();
51 | }
52 |
53 | public void dismiss() {
54 | checked = false;
55 | dismissed();
56 | }
57 |
58 | /**
59 | * 当前被选中
60 | */
61 | public abstract void actived();
62 |
63 | /**
64 | * 当前没有被选中
65 | */
66 | public abstract void dismissed();
67 |
68 | /**
69 | * 获取view
70 | *
71 | * @return
72 | */
73 | public abstract View getView();
74 |
75 | public int getPosition() {
76 | return position;
77 | }
78 |
79 | public void setPosition(int position) {
80 | this.position = position;
81 | }
82 |
83 | public ScalableTabIndicator getScalableTabIndicator() {
84 | return mScalableTabIndicator;
85 | }
86 |
87 | public void setScalableTabIndicator(ScalableTabIndicator scalableTabIndicator) {
88 | mScalableTabIndicator = scalableTabIndicator;
89 | }
90 |
91 | @Override
92 | public void onClick(View v) {
93 | mScalableTabIndicator.setCurrentItem(position);
94 | }
95 |
96 | /**
97 | * 如若需要对tab的item元素进行相关操作,可重写这个方法
98 | *
99 | * @param positionOffset
100 | * @param positionOffsetPixels
101 | */
102 | public void onPageScrolled(float positionOffset, int positionOffsetPixels) {
103 |
104 | }
105 |
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Library
3 |
4 |
--------------------------------------------------------------------------------
/library/src/test/java/com/jiang/android/scalabletabindicator/library/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.jiang.android.scalabletabindicator.library;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------