├── samples ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ └── styles.xml │ │ ├── mipmap-xhdpi │ │ │ ├── mm1.jpg │ │ │ ├── mm2.jpg │ │ │ ├── mm3.jpg │ │ │ ├── mm4.jpg │ │ │ ├── mm5.jpg │ │ │ ├── mm6.jpg │ │ │ ├── mm7.jpg │ │ │ ├── mm8.jpg │ │ │ └── ic_launcher.png │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ ├── layout │ │ │ ├── image_display.xml │ │ │ └── activity_main.xml │ │ └── values-w820dp │ │ │ └── dimens.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── danxx │ │ └── MainActivity.java ├── proguard-rules.pro └── build.gradle ├── tabstrip ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ ├── strings.xml │ │ │ │ └── attrs.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── danxx │ │ │ └── tabstrip │ │ │ └── FlymeTabStrip.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── danxx │ │ │ └── tabstrip │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── danxx │ │ └── tabstrip │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── assets ├── demo.gif └── FlymeTabStrip_Demo_V1.0.2.apk ├── .idea ├── copyright │ └── profiles_settings.xml ├── markdown-navigator │ └── profiles_settings.xml ├── encodings.xml ├── vcs.xml ├── runConfigurations.xml ├── gradle.xml ├── compiler.xml ├── modules.xml ├── misc.xml └── markdown-navigator.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── README.md ├── gradlew.bat └── gradlew /samples/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /tabstrip/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':samples', ':tabstrip' 2 | -------------------------------------------------------------------------------- /assets/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dawish/FlymeTabStrip/HEAD/assets/demo.gif -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dawish/FlymeTabStrip/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /tabstrip/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | TabStrip 3 | 4 | -------------------------------------------------------------------------------- /assets/FlymeTabStrip_Demo_V1.0.2.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dawish/FlymeTabStrip/HEAD/assets/FlymeTabStrip_Demo_V1.0.2.apk -------------------------------------------------------------------------------- /samples/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | FlymeTabStrip 3 | 4 | -------------------------------------------------------------------------------- /samples/src/main/res/mipmap-xhdpi/mm1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dawish/FlymeTabStrip/HEAD/samples/src/main/res/mipmap-xhdpi/mm1.jpg -------------------------------------------------------------------------------- /samples/src/main/res/mipmap-xhdpi/mm2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dawish/FlymeTabStrip/HEAD/samples/src/main/res/mipmap-xhdpi/mm2.jpg -------------------------------------------------------------------------------- /samples/src/main/res/mipmap-xhdpi/mm3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dawish/FlymeTabStrip/HEAD/samples/src/main/res/mipmap-xhdpi/mm3.jpg -------------------------------------------------------------------------------- /samples/src/main/res/mipmap-xhdpi/mm4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dawish/FlymeTabStrip/HEAD/samples/src/main/res/mipmap-xhdpi/mm4.jpg -------------------------------------------------------------------------------- /samples/src/main/res/mipmap-xhdpi/mm5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dawish/FlymeTabStrip/HEAD/samples/src/main/res/mipmap-xhdpi/mm5.jpg -------------------------------------------------------------------------------- /samples/src/main/res/mipmap-xhdpi/mm6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dawish/FlymeTabStrip/HEAD/samples/src/main/res/mipmap-xhdpi/mm6.jpg -------------------------------------------------------------------------------- /samples/src/main/res/mipmap-xhdpi/mm7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dawish/FlymeTabStrip/HEAD/samples/src/main/res/mipmap-xhdpi/mm7.jpg -------------------------------------------------------------------------------- /samples/src/main/res/mipmap-xhdpi/mm8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dawish/FlymeTabStrip/HEAD/samples/src/main/res/mipmap-xhdpi/mm8.jpg -------------------------------------------------------------------------------- /samples/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dawish/FlymeTabStrip/HEAD/samples/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /samples/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dawish/FlymeTabStrip/HEAD/samples/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /samples/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dawish/FlymeTabStrip/HEAD/samples/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /samples/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dawish/FlymeTabStrip/HEAD/samples/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /samples/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dawish/FlymeTabStrip/HEAD/samples/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /samples/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /samples/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Nov 08 11:05:41 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /samples/src/main/res/layout/image_display.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /tabstrip/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /samples/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /samples/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /tabstrip/src/test/java/com/danxx/tabstrip/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.danxx.tabstrip; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /tabstrip/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /samples/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 C:\Users\Dawish\AppData\Local\Android\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 | -------------------------------------------------------------------------------- /tabstrip/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 C:\Users\Dawish\AppData\Local\Android\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 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | -------------------------------------------------------------------------------- /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 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /samples/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /tabstrip/src/androidTest/java/com/danxx/tabstrip/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.danxx.tabstrip; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.danxx.tabstrip.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /tabstrip/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | 4 | android { 5 | compileSdkVersion 25 6 | buildToolsVersion "23.0.3" 7 | 8 | defaultConfig { 9 | minSdkVersion 16 10 | targetSdkVersion 25 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | compile fileTree(dir: 'libs', include: ['*.jar']) 27 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 28 | exclude group: 'com.android.support', module: 'support-annotations' 29 | }) 30 | compile 'com.android.support:appcompat-v7:25.0.1' 31 | testCompile 'junit:junit:4.12' 32 | } 33 | -------------------------------------------------------------------------------- /samples/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | allprojects { 3 | repositories { 4 | maven { url 'https://jitpack.io' } 5 | } 6 | } 7 | android { 8 | compileSdkVersion 25 9 | buildToolsVersion "23.0.3" 10 | defaultConfig { 11 | applicationId "com.danxx" 12 | minSdkVersion 16 13 | targetSdkVersion 25 14 | versionCode 1 15 | versionName "1.0" 16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | compile fileTree(dir: 'libs', include: ['*.jar']) 28 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 29 | exclude group: 'com.android.support', module: 'support-annotations' 30 | }) 31 | compile 'com.android.support:appcompat-v7:25.0.1' 32 | testCompile 'junit:junit:4.12' 33 | // compile project(':tabstrip') 34 | compile 'com.github.Dawish:FlymeTabStrip:v1.0.2' 35 | } 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## FlymeTabStrip 2 | Flyme6 ViewPager TabStrip 3 | 自定义实现Flyme6的ViewPager指示器,实现效果如下: 4 | 5 | ![效果图][1] 6 | 7 | ### 博客地址:[http://blog.csdn.net/u010072711/article/details/54667861](http://blog.csdn.net/u010072711/article/details/54667861) 8 | 9 | ## Gradle 10 | 11 | [![](https://jitpack.io/v/Dawish/FlymeTabStrip.svg)](https://jitpack.io/#Dawish/FlymeTabStrip) 12 | 13 | ``` groovy 14 | allprojects { 15 | repositories { 16 | maven { url 'https://jitpack.io' } 17 | } 18 | } 19 | 20 | dependencies { 21 | compile 'com.github.Dawish:FlymeTabStrip:v1.0.2' 22 | } 23 | ``` 24 | ## Attrs 25 | 26 | ``` xml 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | ``` 42 | ## Example 43 | 44 | ``` java 45 | ViewPager mViewPager = (ViewPager) findViewById(R.id.viewpager); 46 | mViewPager.setAdapter(new ViewPagerAdapter()); 47 | FlymeTabStrip tabStrip = (FlymeTabStrip) findViewById(R.id.tabstrip); 48 | tabStrip.setViewPager(mViewPager); 49 | ``` 50 | 51 | ## Sample 52 | 53 | [Sample sources][2] 54 | 55 | [Sample APK][3] 56 | 57 | [1]: ./assets/demo.gif 58 | [2]: ./samples 59 | [3]: ./assets/FlymeTabStrip_Demo_V1.0.2.apk -------------------------------------------------------------------------------- /samples/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 18 | 28 | 38 | 42 | 43 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.7 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 36 | 37 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /samples/src/main/java/com/danxx/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.danxx; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.support.v4.view.PagerAdapter; 7 | import android.support.v4.view.ViewPager; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.os.Bundle; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.ImageView; 14 | 15 | import com.danxx.tabstrip.FlymeTabStrip; 16 | 17 | public class MainActivity extends AppCompatActivity { 18 | private FlymeTabStrip tabStrip,tabStrip2,tabStrip3; 19 | // private String[] titles = new String[] { "Flyme", "煤油", "杨颜", "白总", "黄总", "安全中心", "黄页", 20 | // "联系人", "电话" }; 21 | private String[] titles = new String[] { "Flyme", "煤油", "杨颜","白永祥"}; 22 | /** 23 | * 指示器偏移宽度 24 | */ 25 | private int offsetWidth = 0; 26 | 27 | private ViewPager mViewPager; 28 | 29 | /** 30 | * viewPager宽度 31 | */ 32 | private int screenWith = 0; 33 | /** 34 | * viewPager高度 35 | */ 36 | private int screeHeight = 0; 37 | 38 | // private int[] drawableResIds = {R.mipmap.mm1,R.mipmap.mm2,R.mipmap.mm3,R.mipmap.mm4,R.mipmap.mm5, 39 | // R.mipmap.mm6,R.mipmap.mm7,R.mipmap.mm8}; 40 | private int[] drawableResIds = {R.mipmap.mm1,R.mipmap.mm2,R.mipmap.mm3,R.mipmap.mm4}; 41 | @Override 42 | protected void onCreate(Bundle savedInstanceState) { 43 | super.onCreate(savedInstanceState); 44 | setContentView(R.layout.activity_main); 45 | 46 | mViewPager = (ViewPager) findViewById(R.id.viewpager); 47 | tabStrip = (FlymeTabStrip) findViewById(R.id.tabstrip); 48 | tabStrip2 = (FlymeTabStrip) findViewById(R.id.tabstrip2); 49 | tabStrip3 = (FlymeTabStrip) findViewById(R.id.tabstrip3); 50 | screenWith = getWindow().getWindowManager().getDefaultDisplay().getWidth(); 51 | screeHeight = getWindow().getWindowManager().getDefaultDisplay().getHeight()-dip2px(this, 45); 52 | //这里之所以是45,请查看布局文件,其中ViewPager以上的节点的高度总和为45 53 | 54 | mViewPager.setAdapter(new ViewPagerAdapter()); 55 | tabStrip.setViewPager(mViewPager); 56 | tabStrip2.setViewPager(mViewPager); 57 | tabStrip3.setViewPager(mViewPager); 58 | } 59 | private class ViewPagerAdapter extends PagerAdapter 60 | { 61 | 62 | @Override 63 | public int getCount() { 64 | return drawableResIds.length; 65 | } 66 | @Override 67 | public Object instantiateItem(ViewGroup container, int position) 68 | { 69 | ImageView imageView = (ImageView) LayoutInflater.from(MainActivity.this).inflate(R.layout.image_display, null); 70 | imageView.setImageBitmap(adjustBitmapSimpleSize(drawableResIds[position])); 71 | imageView.setTag(position); 72 | container.addView(imageView); 73 | 74 | return imageView; 75 | } 76 | 77 | @Override 78 | public void destroyItem(ViewGroup container, int position, Object object) 79 | { 80 | ImageView image = (ImageView)((ViewPager) container).findViewWithTag(position); 81 | ((ViewPager) container).removeView(image); 82 | } 83 | 84 | @Override 85 | public boolean isViewFromObject(View arg0, Object arg1) 86 | { 87 | return arg0==arg1; 88 | } 89 | 90 | @Override 91 | public CharSequence getPageTitle(int position) { 92 | // return super.getPageTitle(position); 93 | return titles[position]; 94 | } 95 | } 96 | /** 97 | * 调整压缩采样率 98 | * @param resId 99 | * @return 100 | */ 101 | private Bitmap adjustBitmapSimpleSize(int resId) 102 | { 103 | BitmapFactory.Options opts = new BitmapFactory.Options(); 104 | opts.inJustDecodeBounds = true; 105 | Bitmap bitmap = BitmapFactory.decodeResource(getResources(),resId, opts); 106 | int visibleHeight = screeHeight; 107 | int visibleWidth = screenWith; 108 | if(opts.outWidth>visibleWidth ||opts.outHeight>visibleHeight) 109 | { 110 | float wRatio = opts.outWidth/visibleWidth; 111 | float hRatio = opts.outHeight/visibleHeight; 112 | opts.inSampleSize = (int) Math.max(wRatio, hRatio); 113 | } 114 | opts.inJustDecodeBounds = false; 115 | if(bitmap!=null){ 116 | bitmap.recycle(); 117 | } 118 | return BitmapFactory.decodeResource(getResources(),resId, opts); 119 | } 120 | 121 | 122 | /** 123 | * 根据手机的分辨率从 dp 的单位 转成为 px(像素) 124 | */ 125 | public static int dip2px(Context context, float dpValue) { 126 | final float scale = context.getResources().getDisplayMetrics().density; 127 | return (int) (dpValue * scale + 0.5f); 128 | } 129 | 130 | /** 131 | * 根据手机的分辨率从 px(像素) 的单位 转成为 dp 132 | */ 133 | public static int px2dip(Context context, float pxValue) { 134 | final float scale = context.getResources().getDisplayMetrics().density; 135 | return (int) (pxValue / scale + 0.5f); 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tabstrip/src/main/java/com/danxx/tabstrip/FlymeTabStrip.java: -------------------------------------------------------------------------------- 1 | package com.danxx.tabstrip; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.content.res.TypedArray; 6 | import android.graphics.Canvas; 7 | import android.graphics.Color; 8 | import android.graphics.Paint; 9 | import android.os.Build; 10 | import android.support.v4.view.PagerAdapter; 11 | import android.support.v4.view.ViewPager; 12 | import android.support.v4.view.ViewPager.OnPageChangeListener; 13 | import android.util.AttributeSet; 14 | import android.util.DisplayMetrics; 15 | import android.util.Log; 16 | import android.util.TypedValue; 17 | import android.view.Gravity; 18 | import android.view.View; 19 | import android.view.ViewTreeObserver.OnGlobalLayoutListener; 20 | import android.widget.HorizontalScrollView; 21 | import android.widget.LinearLayout; 22 | import android.widget.TextView; 23 | 24 | /** 25 | * Flyme6 ViewPager指示器 26 | * @author Dawish_大D 27 | * 博客地址:http://blog.csdn.net/u010072711 28 | */ 29 | public class FlymeTabStrip extends HorizontalScrollView { 30 | private static final String TAG = "TabStrip"; 31 | /** 32 | * 指示器容器 33 | */ 34 | private LinearLayout container; 35 | /** 36 | * 指示器个数 37 | */ 38 | private int tabCount; 39 | /** 40 | * 当前tab位置,默认为0 41 | */ 42 | private int currentPosition = 0; 43 | /** 44 | * 选中的tab位置 45 | */ 46 | private int selectedPosition; 47 | /** 48 | * 49 | */ 50 | private float currentPositionOffset = 0f; 51 | /** 52 | * 53 | */ 54 | private int lastScrollX = 0; 55 | /** 56 | * LayoutParams用于添加指示器到指示器容器中时使用,按等权重分配指示器宽度 57 | */ 58 | private LinearLayout.LayoutParams expandedTabLayoutParams; 59 | /** 60 | * 指示器颜色 61 | */ 62 | private int indicatorColor; 63 | /** 64 | * 文字颜色 65 | */ 66 | private int textColor; 67 | /** 68 | * 文字大小 69 | */ 70 | private int textSize; 71 | /** 72 | * 选中位置的文字大小 73 | */ 74 | private int selectedTextSize; 75 | /** 76 | * 指示器高度 77 | */ 78 | private int indicatorHeight; 79 | /** 80 | * 指示器左右间距 81 | */ 82 | private int indicatorMargin; 83 | /** 84 | * ViewPager 85 | */ 86 | private ViewPager viewPager; 87 | /** 88 | * viewpager的适配器 89 | */ 90 | private PagerAdapter pagerAdapter; 91 | 92 | /** 93 | * page改变监听器 94 | */ 95 | private final PagerStateChangeListener pagerStateChangeListener = new PagerStateChangeListener(); 96 | /** 97 | * 画笔 98 | */ 99 | private Paint paint; 100 | private Context context; 101 | 102 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 103 | public FlymeTabStrip(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 104 | super(context, attrs, defStyleAttr, defStyleRes); 105 | init(context, attrs, defStyleAttr, defStyleRes); 106 | } 107 | 108 | public FlymeTabStrip(Context context, AttributeSet attrs, int defStyleAttr) { 109 | super(context, attrs, defStyleAttr); 110 | init(context, attrs, defStyleAttr, 0); 111 | } 112 | 113 | public FlymeTabStrip(Context context, AttributeSet attrs) { 114 | super(context, attrs); 115 | init(context, attrs, 0, 0); 116 | } 117 | 118 | public FlymeTabStrip(Context context) { 119 | super(context); 120 | init(context, null, 0, 0); 121 | } 122 | 123 | /** 124 | * 初始化 125 | * 126 | * @param context 127 | * @param attrs 128 | * @param defStyleAttr 129 | * @param defStyleRes 130 | */ 131 | private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 132 | this.context = context; 133 | // 取消横向的滚动条 134 | setHorizontalScrollBarEnabled(false); 135 | // 指示器容器初始化 136 | container = new LinearLayout(context); 137 | container.setOrientation(LinearLayout.HORIZONTAL); 138 | container.setLayoutParams(new LayoutParams( 139 | android.widget.LinearLayout.LayoutParams.MATCH_PARENT, 140 | android.widget.LinearLayout.LayoutParams.MATCH_PARENT)); 141 | // 添加指示器容器到scrollview 142 | addView(container); 143 | 144 | // 获取屏幕相关信息 145 | DisplayMetrics dm = getResources().getDisplayMetrics(); 146 | 147 | TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, 148 | R.styleable.FlymeTabStrip, defStyleAttr, defStyleRes); 149 | int n = typedArray.getIndexCount(); 150 | for (int i = 0; i < n; i++) { 151 | int attr = typedArray.getIndex(i); 152 | if (attr == R.styleable.FlymeTabStrip_indicatorColor) { 153 | indicatorColor = typedArray.getColor(attr, Color.YELLOW); 154 | 155 | // 指示器高度,默认2 156 | } else if (attr == R.styleable.FlymeTabStrip_indicatorHeight) { 157 | indicatorHeight = typedArray.getDimensionPixelSize(attr, 2); 158 | 159 | // 指示器左右间距,默认20 160 | } else if (attr == R.styleable.FlymeTabStrip_indicatorMargin) { 161 | indicatorMargin = typedArray.getDimensionPixelSize(attr, 20); 162 | 163 | // 文字颜色,默认黑色 164 | } else if (attr == R.styleable.FlymeTabStrip_indicatorTextColor) { 165 | textColor = typedArray.getColor(attr, Color.BLACK); 166 | 167 | // 文字大小,默认15 168 | } else if (attr == R.styleable.FlymeTabStrip_indicatorTextSize) { 169 | textSize = typedArray.getDimensionPixelSize(attr, (int) TypedValue.applyDimension( 170 | TypedValue.COMPLEX_UNIT_SP, 15, dm)) / 3; 171 | 172 | // 选中项的文字大小,默认18 173 | } else if (attr == R.styleable.FlymeTabStrip_selectedIndicatorTextSize) { 174 | selectedTextSize = typedArray.getDimensionPixelSize(attr, (int) TypedValue.applyDimension( 175 | TypedValue.COMPLEX_UNIT_SP, 18, dm)) / 3; 176 | 177 | } else { 178 | } 179 | } 180 | // typedArray回收 181 | typedArray.recycle(); 182 | 183 | expandedTabLayoutParams = new LinearLayout.LayoutParams(0, 184 | LayoutParams.MATCH_PARENT, 1.0f); 185 | // 初始化画笔 186 | paint = new Paint(); 187 | } 188 | 189 | @Override 190 | protected void onDraw(Canvas canvas) { 191 | super.onDraw(canvas); 192 | // 如果指示器个数为0,直接结束绘画 193 | if (tabCount == 0) { 194 | return; 195 | } 196 | // 获取onMeasure后的高 197 | final int height = getHeight(); 198 | /* 199 | * 画指示器下方的线 200 | */ 201 | // 设置颜色 202 | paint.setColor(indicatorColor); 203 | // 当前指示tab位置 204 | View currentTab = container.getChildAt(currentPosition); 205 | // 当前tab的左边相对父容器的左边距 206 | float leftPadding = currentTab.getLeft(); 207 | // 当前tab的右边相对于父容器左边距 208 | float rightPadding = currentTab.getRight(); 209 | float tempPadding = 20; 210 | // 如果出现位移 211 | 212 | float centerPosition = 0.0f; 213 | 214 | if (currentPositionOffset >= 0f && currentPosition < tabCount - 1) { 215 | View nextTab = container.getChildAt(currentPosition + 1); 216 | final float nextTabLeft = nextTab.getLeft(); 217 | final float nextTabRight = nextTab.getRight(); 218 | // 位置是在滑动过程中不断变化的 219 | leftPadding = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * leftPadding); 220 | rightPadding = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * rightPadding); 221 | } 222 | centerPosition = (rightPadding - leftPadding)/2 + leftPadding; 223 | float left = centerPosition - tempPadding - formatPercent(currentPositionOffset)*tempPadding; 224 | float right = centerPosition + tempPadding + formatPercent(currentPositionOffset)*tempPadding; 225 | 226 | // 绘制 227 | canvas.drawRect(left, height - indicatorHeight, right, height, paint); 228 | 229 | } 230 | 231 | /** 232 | * 设置ViewPager 233 | * 234 | * @param viewPager 235 | */ 236 | public void setViewPager(ViewPager viewPager) { 237 | this.viewPager = viewPager; 238 | if (viewPager.getAdapter() == null) { 239 | throw new IllegalStateException( 240 | "ViewPager does not has a adapter instance"); 241 | } else { 242 | pagerAdapter = viewPager.getAdapter(); 243 | } 244 | viewPager.addOnPageChangeListener(pagerStateChangeListener); 245 | update(); 246 | } 247 | 248 | /** 249 | * 更新界面 250 | */ 251 | private void update() { 252 | // 指示器容器移除所有子view 253 | container.removeAllViews(); 254 | // 获取指示器个数 255 | tabCount = pagerAdapter.getCount(); 256 | // 逐个添加指示器 257 | for (int i = 0; i < tabCount; i++) { 258 | addTab(i, pagerAdapter.getPageTitle(i)); 259 | } 260 | // 更新Tab样式 261 | updateTabStyle(); 262 | getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 263 | @Override 264 | public void onGlobalLayout() { 265 | getViewTreeObserver().removeOnGlobalLayoutListener(this); 266 | currentPosition = viewPager.getCurrentItem(); 267 | scrollToChild(currentPosition, 0); 268 | } 269 | }); 270 | } 271 | 272 | /** 273 | * 滑动ScrollView 274 | * 275 | * @param position 276 | * @param offset 277 | */ 278 | private void scrollToChild(int position, int offset) { 279 | if (tabCount == 0) { 280 | return; 281 | } 282 | int newScrollX = container.getChildAt(position).getLeft() + offset; 283 | if (newScrollX != lastScrollX) { 284 | lastScrollX = newScrollX; 285 | scrollTo(newScrollX, 0); 286 | } 287 | } 288 | 289 | /** 290 | * 添加指示器 291 | * 292 | * @param position 293 | * @param title 294 | */ 295 | private void addTab(final int position, CharSequence title) { 296 | TextView tvTab = new TextView(context); 297 | tvTab.setText(title); 298 | tvTab.setTextColor(textColor); 299 | tvTab.setTextSize(textSize); 300 | tvTab.setGravity(Gravity.CENTER); 301 | tvTab.setSingleLine(); 302 | tvTab.setFocusable(true); 303 | tvTab.setOnClickListener(new OnClickListener() { 304 | 305 | @Override 306 | public void onClick(View v) { 307 | viewPager.setCurrentItem(position); 308 | } 309 | }); 310 | tvTab.setPadding(indicatorMargin, 0, indicatorMargin, 0); 311 | container.addView(tvTab, position, expandedTabLayoutParams); 312 | } 313 | 314 | /** 315 | * 更新指示器样式 316 | */ 317 | private void updateTabStyle() { 318 | for (int i = 0; i < tabCount; i++) { 319 | TextView tab = (TextView) container.getChildAt(i); 320 | if (i == selectedPosition) { 321 | // 设置选中的指示器文字颜色和大小 322 | tab.setTextColor(indicatorColor); 323 | tab.setTextSize(selectedTextSize); 324 | } else { 325 | tab.setTextColor(textColor); 326 | tab.setTextSize(textSize); 327 | } 328 | } 329 | } 330 | 331 | /** 332 | * 对偏移百分比进行格式化 保证是一个小到大 然后到小的一个驼峰过程 333 | * 这样才能保证滚动指示器是一个长度在随着滚动偏移不断变化的样子 334 | * @param percent 335 | * @return 336 | */ 337 | private float formatPercent(float percent){ 338 | 339 | float adsP = (float) Math.abs(percent - 0.5f); 340 | 341 | float valueP = Math.abs(0.5f - adsP); 342 | return valueP; 343 | } 344 | 345 | /** 346 | * viewPager状态改变监听 347 | * 348 | */ 349 | private class PagerStateChangeListener implements OnPageChangeListener { 350 | 351 | /** 352 | * viewpager状态监听 353 | * @param state 354 | */ 355 | @Override 356 | public void onPageScrollStateChanged(int state) { 357 | if (state == ViewPager.SCROLL_STATE_IDLE) { // 0 空闲状态 pager处于空闲状态 358 | scrollToChild(viewPager.getCurrentItem(), 0); 359 | }else if(state == ViewPager.SCROLL_STATE_SETTLING){ // 2 正在自动沉降,相当于松手后,pager恢复到一个完整pager的过程 360 | 361 | }else if(state == ViewPager.SCROLL_STATE_DRAGGING){ // 1 viewpager正在被滑动,处于正在拖拽中 362 | 363 | } 364 | } 365 | 366 | /** 367 | * viewpager正在滑动,会回调一些偏移量 368 | * 滚动时,只要处理指示器下方横线的滚动 369 | * @param position 当前页面 370 | * @param positionOffset 当前页面偏移的百分比 371 | * @param positionOffsetPixels 当前页面偏移的像素值 372 | */ 373 | @Override 374 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 375 | currentPosition = position; 376 | currentPositionOffset = positionOffset; 377 | // 处理指示器下方横线的滚动,scrollToChild会不断调用ondraw方法,绘制在重绘下划线,这就是移动动画效果 378 | scrollToChild(position, (int) (positionOffset * container.getChildAt(position).getWidth())); 379 | invalidate(); 380 | } 381 | 382 | /** 383 | * page滚动结束 384 | * @param position 滚动结束后选中的页面 385 | */ 386 | @Override 387 | public void onPageSelected(int position) { 388 | // 滚动结束后的未知 389 | selectedPosition = position; 390 | // 更新指示器状态 391 | updateTabStyle(); 392 | } 393 | 394 | } 395 | } 396 | --------------------------------------------------------------------------------