├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE ├── README.md ├── build.gradle ├── demo.png ├── demo_gif.gif ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle ├── verticaltablayout ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── q │ │ └── rorbin │ │ └── verticaltablayout │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── q │ │ │ └── rorbin │ │ │ └── verticaltablayout │ │ │ ├── VerticalTabLayout.java │ │ │ ├── adapter │ │ │ ├── SimpleTabAdapter.java │ │ │ └── TabAdapter.java │ │ │ ├── util │ │ │ ├── DisplayUtil.java │ │ │ └── TabFragmentManager.java │ │ │ └── widget │ │ │ ├── ITabView.java │ │ │ ├── QTabView.java │ │ │ ├── TabBadgeView.java │ │ │ └── TabView.java │ └── res │ │ ├── drawable-hdpi │ │ ├── man_01_none.png │ │ ├── man_01_pressed.png │ │ ├── man_02_none.png │ │ ├── man_02_pressed.png │ │ ├── man_03_none.png │ │ ├── man_03_pressed.png │ │ ├── man_04_none.png │ │ └── man_04_pressed.png │ │ ├── layout │ │ └── item_qtabview.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ └── strings.xml │ └── test │ └── java │ └── q │ └── rorbin │ └── verticaltablayout │ └── ExampleUnitTest.java └── verticaltablayoutdemo ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src ├── androidTest └── java │ └── q │ └── rorbin │ └── verticaltablayoutdemo │ └── ApplicationTest.java ├── main ├── AndroidManifest.xml ├── java │ └── q │ │ └── rorbin │ │ └── verticaltablayoutdemo │ │ ├── MainActivity.java │ │ ├── MenuBean.java │ │ ├── TabFragment.java │ │ └── TabFragmentActivity.java └── res │ ├── layout │ ├── activity_main.xml │ └── activity_tab_fragment.xml │ ├── menu │ └── menu_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── test └── java └── q └── rorbin └── verticaltablayoutdemo └── ExampleUnitTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | VerticalTabLayout -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 24 | 25 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 该项目已废弃停止维护, 请不要再您的生产环境中使用 2 | 3 | # VerticalTabLayout 4 | [ ![Download](https://api.bintray.com/packages/qstumn/maven/VerticalTabLayout/images/download.svg) ](https://bintray.com/qstumn/maven/VerticalTabLayout/_latestVersion) 5 | 6 | 垂直竖向的Android TabLayout 7 | 8 | ![](https://github.com/qstumn/VerticalTabLayout/blob/master/demo.png?raw=true) 9 | 10 | ### 一些特性 11 | * 支持自定义Indicator大小 12 | 13 | * 支持自定义Indicator位置 14 | 15 | * 支持Indicator设置圆角 16 | 17 | * 支持Tab设置Badge 18 | 19 | * 支持Adapter的方式创建Tab 20 | 21 | * 多种Tab高度设置模式 22 | 23 | * Tab支持android:state_selected 24 | 25 | * 很方便的和ViewPager结合使用 26 | 27 | * 很方便的和Fragment结合使用 28 | 29 | ![](https://github.com/qstumn/VerticalTabLayout/blob/master/demo_gif.gif?raw=true) 30 | 31 | ## how to use: 32 | ### 1. gradle 33 | ```groovy 34 | compile 'q.rorbin:VerticalTabLayout:1.2.5' 35 | ``` 36 | VERSION_CODE : [here](https://github.com/qstumn/VerticalTabLayout/releases) 37 | ### 2. xml 38 | ```xml 39 | 48 | ``` 49 | 50 | ### 3. 属性说明 51 | 52 | xml | code | 说明 53 | ---|---|--- 54 | app:indicator_color | setIndicatorColor | 指示器颜色 55 | app:indicator_width | setIndicatorWidth | 指示器宽度 56 | app:indicator_gravity | setIndicatorGravity | 指示器位置 57 | app:indicator_corners | setIndicatorCorners | 指示器圆角 58 | app:tab_mode | setTabMode | Tab高度模式 59 | app:tab_height | setTabHeight | Tab高度 60 | app:tab_margin | setTabMargin | Tab间距 61 | 62 | ### 4. 创建Tab的方式 63 | - 普通方式创建 64 | ```java 65 | tablayout.addTab(new QTabView(context)) 66 | tablayout.addOnTabSelectedListener(new VerticalTabLayout.OnTabSelectedListener() { 67 | @Override 68 | public void onTabSelected(TabView tab, int position) { 69 | 70 | } 71 | 72 | @Override 73 | public void onTabReselected(TabView tab, int position) { 74 | 75 | } 76 | }); 77 | ``` 78 | - Adapter方式创建 79 | ```java 80 | tablayout.setTabAdapter(new TabAdapter() { 81 | @Override 82 | public int getCount() { 83 | return 0; 84 | } 85 | 86 | @Override 87 | public TabView.TabBadge getBadge(int position) { 88 | return null; 89 | } 90 | 91 | @Override 92 | public TabView.TabIcon getIcon(int position) { 93 | return null; 94 | } 95 | 96 | @Override 97 | public TabView.TabTitle getTitle(int position) { 98 | return null; 99 | } 100 | 101 | @Override 102 | public int getBackground(int position) { 103 | return 0; 104 | } 105 |     }); 106 | ``` 107 | 按照自己的需要进行返回相应的值即可,不需要的返回0或者null 108 | 也可以选择使用SimpleTabAdapter,内部空实现了TabAdapter的所有方法 109 | TabBadge、TabIcon、TabTitle使用build模式创建。 110 | 111 | - 结合ViewPager使用 112 | ```java 113 | tablayout.setupWithViewPager(viewpager); 114 | ``` 115 | ViewPager的PagerAdapter可选择实现TabAdapter接口 116 | 117 | 如果您需要使用垂直竖向的ViewPager,推荐您使用:https://github.com/youngkaaa/YViewPagerDemo 118 | 119 | - 结合Fragment使用 120 | ```java 121 | tabLayout.setupWithFragment(FragmentManager manager, int containerResid, List fragments, TabAdapter adapter) 122 | ``` 123 | ### 5. 设置badge 124 | ```java 125 | int tabPosition = 3; 126 | int badgeNum = 55; 127 | tablayout.setTabBadge(tabPosition,badgeNum); 128 | Badge badge = tablayout.getTabAt(position).getBadgeView(); 129 | 130 | Badge使用方法请移步https://github.com/qstumn/BadgeView 131 | ``` 132 | 133 | ### 6.更新计划 134 | 抽象解耦Indicator,实现绘制任意形状Indicator 135 | # LICENSE 136 | ``` 137 | Copyright 2016, RorbinQiu 138 | 139 | Licensed under the Apache License, Version 2.0 (the "License"); 140 | you may not use this file except in compliance with the License. 141 | You may obtain a copy of the License at 142 | 143 | http://www.apache.org/licenses/LICENSE-2.0 144 | 145 | Unless required by applicable law or agreed to in writing, software 146 | distributed under the License is distributed on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 148 | See the License for the specific language governing permissions and 149 | limitations under the License. 150 | ``` 151 | -------------------------------------------------------------------------------- /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:2.3.3' 9 | classpath 'com.novoda:bintray-release:0.4.0' 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qstumn/VerticalTabLayout/7588fc6766c097132aadcf37940aaea59e9f2e8e/demo.png -------------------------------------------------------------------------------- /demo_gif.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qstumn/VerticalTabLayout/7588fc6766c097132aadcf37940aaea59e9f2e8e/demo_gif.gif -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | ## Project-wide Gradle settings. 2 | # 3 | # For more details on how to configure your build environment visit 4 | # http://www.gradle.org/docs/current/userguide/build_environment.html 5 | # 6 | # Specifies the JVM arguments used for the daemon process. 7 | # The setting is particularly useful for tweaking memory settings. 8 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 10 | # 11 | # When configured, Gradle will run in incubating parallel mode. 12 | # This option should only be used with decoupled projects. More details, visit 13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 14 | # org.gradle.parallel=true 15 | #Fri Aug 05 09:25:54 CST 2016 16 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qstumn/VerticalTabLayout/7588fc6766c097132aadcf37940aaea59e9f2e8e/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Mar 03 09:25:44 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-3.3-all.zip 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':verticaltablayoutdemo',':verticaltablayout' 2 | -------------------------------------------------------------------------------- /verticaltablayout/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /verticaltablayout/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.novoda.bintray-release' 3 | 4 | android { 5 | compileSdkVersion 25 6 | buildToolsVersion '25.0.0' 7 | 8 | defaultConfig { 9 | minSdkVersion 14 10 | targetSdkVersion 25 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 | lintOptions { 21 | disable 'RestrictedApi' 22 | } 23 | } 24 | 25 | publish { 26 | userOrg = 'qstumn' 27 | groupId = 'q.rorbin' 28 | artifactId = 'VerticalTabLayout' 29 | publishVersion = '1.2.3' 30 | desc = 'This is a vertical direction TabLayout' 31 | website = 'https://github.com/qstumn/VerticalTabLayout' 32 | } 33 | 34 | dependencies { 35 | compile fileTree(include: ['*.jar'], dir: 'libs') 36 | testCompile 'junit:junit:4.12' 37 | provided 'com.android.support:support-v4:25.3.0' 38 | compile 'q.rorbin:badgeview:1.1.2' 39 | } 40 | -------------------------------------------------------------------------------- /verticaltablayout/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 E:\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 | -------------------------------------------------------------------------------- /verticaltablayout/src/androidTest/java/q/rorbin/verticaltablayout/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package q.rorbin.verticaltablayout; 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 | } -------------------------------------------------------------------------------- /verticaltablayout/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /verticaltablayout/src/main/java/q/rorbin/verticaltablayout/VerticalTabLayout.java: -------------------------------------------------------------------------------- 1 | package q.rorbin.verticaltablayout; 2 | 3 | import android.animation.AnimatorSet; 4 | import android.animation.ValueAnimator; 5 | import android.content.Context; 6 | import android.content.res.TypedArray; 7 | import android.database.DataSetObserver; 8 | import android.graphics.Canvas; 9 | import android.graphics.Paint; 10 | import android.graphics.RectF; 11 | import android.support.annotation.Nullable; 12 | import android.support.v4.app.Fragment; 13 | import android.support.v4.app.FragmentManager; 14 | import android.support.v4.view.PagerAdapter; 15 | import android.support.v4.view.ViewPager; 16 | import android.util.AttributeSet; 17 | import android.view.Gravity; 18 | import android.view.View; 19 | import android.widget.LinearLayout; 20 | import android.widget.ScrollView; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | import q.rorbin.verticaltablayout.adapter.TabAdapter; 26 | import q.rorbin.verticaltablayout.util.DisplayUtil; 27 | import q.rorbin.verticaltablayout.util.TabFragmentManager; 28 | import q.rorbin.verticaltablayout.widget.QTabView; 29 | import q.rorbin.verticaltablayout.widget.TabView; 30 | 31 | import static android.support.v4.view.ViewPager.SCROLL_STATE_IDLE; 32 | import static android.support.v4.view.ViewPager.SCROLL_STATE_SETTLING; 33 | 34 | /** 35 | * @author chqiu 36 | * Email:qstumn@163.com 37 | */ 38 | public class VerticalTabLayout extends ScrollView { 39 | private Context mContext; 40 | private TabStrip mTabStrip; 41 | private int mColorIndicator; 42 | private TabView mSelectedTab; 43 | private int mTabMargin; 44 | private int mIndicatorWidth; 45 | private int mIndicatorGravity; 46 | private float mIndicatorCorners; 47 | private int mTabMode; 48 | private int mTabHeight; 49 | 50 | public static int TAB_MODE_FIXED = 10; 51 | public static int TAB_MODE_SCROLLABLE = 11; 52 | 53 | private ViewPager mViewPager; 54 | private PagerAdapter mPagerAdapter; 55 | private TabAdapter mTabAdapter; 56 | 57 | private List mTabSelectedListeners; 58 | private OnTabPageChangeListener mTabPageChangeListener; 59 | private DataSetObserver mPagerAdapterObserver; 60 | 61 | private TabFragmentManager mTabFragmentManager; 62 | 63 | public VerticalTabLayout(Context context) { 64 | this(context, null); 65 | } 66 | 67 | public VerticalTabLayout(Context context, AttributeSet attrs) { 68 | this(context, attrs, 0); 69 | } 70 | 71 | public VerticalTabLayout(Context context, AttributeSet attrs, int defStyleAttr) { 72 | super(context, attrs, defStyleAttr); 73 | mContext = context; 74 | mTabSelectedListeners = new ArrayList<>(); 75 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.VerticalTabLayout); 76 | mColorIndicator = typedArray.getColor(R.styleable.VerticalTabLayout_indicator_color, 77 | context.getResources().getColor(R.color.colorAccent)); 78 | mIndicatorWidth = (int) typedArray.getDimension(R.styleable.VerticalTabLayout_indicator_width, DisplayUtil.dp2px(context, 3)); 79 | mIndicatorCorners = typedArray.getDimension(R.styleable.VerticalTabLayout_indicator_corners, 0); 80 | mIndicatorGravity = typedArray.getInteger(R.styleable.VerticalTabLayout_indicator_gravity, Gravity.LEFT); 81 | if (mIndicatorGravity == 3) { 82 | mIndicatorGravity = Gravity.LEFT; 83 | } else if (mIndicatorGravity == 5) { 84 | mIndicatorGravity = Gravity.RIGHT; 85 | } else if (mIndicatorGravity == 119) { 86 | mIndicatorGravity = Gravity.FILL; 87 | } 88 | mTabMargin = (int) typedArray.getDimension(R.styleable.VerticalTabLayout_tab_margin, 0); 89 | mTabMode = typedArray.getInteger(R.styleable.VerticalTabLayout_tab_mode, TAB_MODE_FIXED); 90 | int defaultTabHeight = LinearLayout.LayoutParams.WRAP_CONTENT; 91 | mTabHeight = (int) typedArray.getDimension(R.styleable.VerticalTabLayout_tab_height, defaultTabHeight); 92 | typedArray.recycle(); 93 | } 94 | 95 | @Override 96 | protected void onFinishInflate() { 97 | super.onFinishInflate(); 98 | if (getChildCount() > 0) removeAllViews(); 99 | initTabStrip(); 100 | } 101 | 102 | private void initTabStrip() { 103 | mTabStrip = new TabStrip(mContext); 104 | addView(mTabStrip, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 105 | } 106 | 107 | public void removeAllTabs() { 108 | mTabStrip.removeAllViews(); 109 | mSelectedTab = null; 110 | } 111 | 112 | public TabView getTabAt(int position) { 113 | return (TabView) mTabStrip.getChildAt(position); 114 | } 115 | 116 | public int getTabCount() { 117 | return mTabStrip.getChildCount(); 118 | } 119 | 120 | public int getSelectedTabPosition() { 121 | int index = mTabStrip.indexOfChild(mSelectedTab); 122 | return index == -1 ? 0 : index; 123 | } 124 | 125 | private void addTabWithMode(TabView tabView) { 126 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 127 | initTabWithMode(params); 128 | mTabStrip.addView(tabView, params); 129 | if (mTabStrip.indexOfChild(tabView) == 0) { 130 | tabView.setChecked(true); 131 | params = (LinearLayout.LayoutParams) tabView.getLayoutParams(); 132 | params.setMargins(0, 0, 0, 0); 133 | tabView.setLayoutParams(params); 134 | mSelectedTab = tabView; 135 | mTabStrip.post(new Runnable() { 136 | @Override 137 | public void run() { 138 | mTabStrip.moveIndicator(0); 139 | } 140 | }); 141 | } 142 | } 143 | 144 | private void initTabWithMode(LinearLayout.LayoutParams params) { 145 | if (mTabMode == TAB_MODE_FIXED) { 146 | params.height = 0; 147 | params.weight = 1.0f; 148 | params.setMargins(0, 0, 0, 0); 149 | setFillViewport(true); 150 | } else if (mTabMode == TAB_MODE_SCROLLABLE) { 151 | params.height = mTabHeight; 152 | params.weight = 0f; 153 | params.setMargins(0, mTabMargin, 0, 0); 154 | setFillViewport(false); 155 | } 156 | } 157 | 158 | private void scrollToTab(int position) { 159 | final TabView tabView = getTabAt(position); 160 | int y = getScrollY(); 161 | int tabTop = tabView.getTop() + tabView.getHeight() / 2 - y; 162 | int target = getHeight() / 2; 163 | if (tabTop > target) { 164 | smoothScrollBy(0, tabTop - target); 165 | } else if (tabTop < target) { 166 | smoothScrollBy(0, tabTop - target); 167 | } 168 | } 169 | 170 | private float mLastPositionOffset; 171 | 172 | private void scrollByTab(int position, final float positionOffset) { 173 | final TabView tabView = getTabAt(position); 174 | int y = getScrollY(); 175 | int tabTop = tabView.getTop() + tabView.getHeight() / 2 - y; 176 | int target = getHeight() / 2; 177 | int nextScrollY = tabView.getHeight() + mTabMargin; 178 | if (positionOffset > 0) { 179 | float percent = positionOffset - mLastPositionOffset; 180 | if (tabTop > target) { 181 | smoothScrollBy(0, (int) (nextScrollY * percent)); 182 | } 183 | } 184 | mLastPositionOffset = positionOffset; 185 | } 186 | 187 | public void addTab(TabView tabView) { 188 | if (tabView != null) { 189 | addTabWithMode(tabView); 190 | tabView.setOnClickListener(new OnClickListener() { 191 | @Override 192 | public void onClick(View view) { 193 | int position = mTabStrip.indexOfChild(view); 194 | setTabSelected(position); 195 | } 196 | }); 197 | } else { 198 | throw new IllegalStateException("tabview can't be null"); 199 | } 200 | } 201 | 202 | public void setTabSelected(final int position) { 203 | setTabSelected(position, true, true); 204 | } 205 | 206 | private void setTabSelected(final int position, final boolean updataIndicator, final boolean callListener) { 207 | post(new Runnable() { 208 | @Override 209 | public void run() { 210 | setTabSelectedImpl(position, updataIndicator, callListener); 211 | } 212 | }); 213 | } 214 | 215 | private void setTabSelectedImpl(final int position, boolean updataIndicator, boolean callListener) { 216 | TabView view = getTabAt(position); 217 | boolean selected; 218 | if (selected = (view != mSelectedTab)) { 219 | if (mSelectedTab != null) { 220 | mSelectedTab.setChecked(false); 221 | } 222 | view.setChecked(true); 223 | if (updataIndicator) { 224 | mTabStrip.moveIndicatorWithAnimator(position); 225 | } 226 | mSelectedTab = view; 227 | scrollToTab(position); 228 | } 229 | if (callListener) { 230 | for (int i = 0; i < mTabSelectedListeners.size(); i++) { 231 | OnTabSelectedListener listener = mTabSelectedListeners.get(i); 232 | if (listener != null) { 233 | if (selected) { 234 | listener.onTabSelected(view, position); 235 | } else { 236 | listener.onTabReselected(view, position); 237 | } 238 | } 239 | } 240 | } 241 | } 242 | 243 | public void setTabBadge(int tabPosition, int badgeNum) { 244 | getTabAt(tabPosition).getBadgeView().setBadgeNumber(badgeNum); 245 | } 246 | 247 | public void setTabBadge(int tabPosition, String badgeText) { 248 | getTabAt(tabPosition).getBadgeView().setBadgeText(badgeText); 249 | } 250 | 251 | public void setTabMode(int mode) { 252 | if (mode != TAB_MODE_FIXED && mode != TAB_MODE_SCROLLABLE) { 253 | throw new IllegalStateException("only support TAB_MODE_FIXED or TAB_MODE_SCROLLABLE"); 254 | } 255 | if (mode == mTabMode) return; 256 | mTabMode = mode; 257 | for (int i = 0; i < mTabStrip.getChildCount(); i++) { 258 | View view = mTabStrip.getChildAt(i); 259 | LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams(); 260 | initTabWithMode(params); 261 | if (i == 0) { 262 | params.setMargins(0, 0, 0, 0); 263 | } 264 | view.setLayoutParams(params); 265 | } 266 | mTabStrip.invalidate(); 267 | mTabStrip.post(new Runnable() { 268 | @Override 269 | public void run() { 270 | mTabStrip.updataIndicator(); 271 | } 272 | }); 273 | } 274 | 275 | /** 276 | * only in TAB_MODE_SCROLLABLE mode will be supported 277 | * 278 | * @param margin margin 279 | */ 280 | public void setTabMargin(int margin) { 281 | if (margin == mTabMargin) return; 282 | mTabMargin = margin; 283 | if (mTabMode == TAB_MODE_FIXED) return; 284 | for (int i = 0; i < mTabStrip.getChildCount(); i++) { 285 | View view = mTabStrip.getChildAt(i); 286 | LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams(); 287 | params.setMargins(0, i == 0 ? 0 : mTabMargin, 0, 0); 288 | view.setLayoutParams(params); 289 | } 290 | mTabStrip.invalidate(); 291 | mTabStrip.post(new Runnable() { 292 | @Override 293 | public void run() { 294 | mTabStrip.updataIndicator(); 295 | } 296 | }); 297 | } 298 | 299 | /** 300 | * only in TAB_MODE_SCROLLABLE mode will be supported 301 | * 302 | * @param height height 303 | */ 304 | public void setTabHeight(int height) { 305 | if (height == mTabHeight) return; 306 | mTabHeight = height; 307 | if (mTabMode == TAB_MODE_FIXED) return; 308 | for (int i = 0; i < mTabStrip.getChildCount(); i++) { 309 | View view = mTabStrip.getChildAt(i); 310 | LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams(); 311 | params.height = mTabHeight; 312 | view.setLayoutParams(params); 313 | } 314 | mTabStrip.invalidate(); 315 | mTabStrip.post(new Runnable() { 316 | @Override 317 | public void run() { 318 | mTabStrip.updataIndicator(); 319 | } 320 | }); 321 | } 322 | 323 | public void setIndicatorColor(int color) { 324 | mColorIndicator = color; 325 | mTabStrip.invalidate(); 326 | } 327 | 328 | public void setIndicatorWidth(int width) { 329 | mIndicatorWidth = width; 330 | mTabStrip.setIndicatorGravity(); 331 | } 332 | 333 | public void setIndicatorCorners(int corners) { 334 | mIndicatorCorners = corners; 335 | mTabStrip.invalidate(); 336 | } 337 | 338 | /** 339 | * @param gravity only support Gravity.LEFT,Gravity.RIGHT,Gravity.FILL 340 | */ 341 | public void setIndicatorGravity(int gravity) { 342 | if (gravity == Gravity.LEFT || gravity == Gravity.RIGHT || Gravity.FILL == gravity) { 343 | mIndicatorGravity = gravity; 344 | mTabStrip.setIndicatorGravity(); 345 | } else { 346 | throw new IllegalStateException("only support Gravity.LEFT,Gravity.RIGHT,Gravity.FILL"); 347 | } 348 | } 349 | 350 | // public void setTabPadding(int padding) { 351 | // 352 | // } 353 | // 354 | // public void setTabPadding(int start, int top, int end, int bottom) { 355 | // 356 | // } 357 | 358 | public void addOnTabSelectedListener(OnTabSelectedListener listener) { 359 | if (listener != null) { 360 | mTabSelectedListeners.add(listener); 361 | } 362 | } 363 | 364 | public void removeOnTabSelectedListener(OnTabSelectedListener listener) { 365 | if (listener != null) { 366 | mTabSelectedListeners.remove(listener); 367 | } 368 | } 369 | 370 | public void setTabAdapter(TabAdapter adapter) { 371 | removeAllTabs(); 372 | if (adapter != null) { 373 | mTabAdapter = adapter; 374 | for (int i = 0; i < adapter.getCount(); i++) { 375 | addTab(new QTabView(mContext).setIcon(adapter.getIcon(i)) 376 | .setTitle(adapter.getTitle(i)).setBadge(adapter.getBadge(i)) 377 | .setBackground(adapter.getBackground(i))); 378 | } 379 | } 380 | } 381 | 382 | public void setupWithFragment(FragmentManager manager, List fragments) { 383 | setupWithFragment(manager, 0, fragments); 384 | } 385 | 386 | public void setupWithFragment(FragmentManager manager, List fragments, TabAdapter adapter) { 387 | setupWithFragment(manager, 0, fragments, adapter); 388 | } 389 | 390 | public void setupWithFragment(FragmentManager manager, int containerResid, List fragments) { 391 | if (mTabFragmentManager != null) { 392 | mTabFragmentManager.detach(); 393 | } 394 | if (containerResid != 0) { 395 | mTabFragmentManager = new TabFragmentManager(manager, containerResid, fragments, this); 396 | } else { 397 | mTabFragmentManager = new TabFragmentManager(manager, fragments, this); 398 | } 399 | } 400 | 401 | public void setupWithFragment(FragmentManager manager, int containerResid, List fragments, TabAdapter adapter) { 402 | setTabAdapter(adapter); 403 | setupWithFragment(manager, containerResid, fragments); 404 | } 405 | 406 | public void setupWithViewPager(@Nullable ViewPager viewPager) { 407 | if (mViewPager != null && mTabPageChangeListener != null) { 408 | mViewPager.removeOnPageChangeListener(mTabPageChangeListener); 409 | } 410 | 411 | if (viewPager != null) { 412 | final PagerAdapter adapter = viewPager.getAdapter(); 413 | if (adapter == null) { 414 | throw new IllegalArgumentException("ViewPager does not have a PagerAdapter set"); 415 | } 416 | 417 | mViewPager = viewPager; 418 | 419 | if (mTabPageChangeListener == null) { 420 | mTabPageChangeListener = new OnTabPageChangeListener(); 421 | } 422 | viewPager.addOnPageChangeListener(mTabPageChangeListener); 423 | 424 | addOnTabSelectedListener(new OnTabSelectedListener() { 425 | @Override 426 | public void onTabSelected(TabView tab, int position) { 427 | if (mViewPager != null && mViewPager.getAdapter().getCount() >= position) { 428 | mViewPager.setCurrentItem(position); 429 | } 430 | } 431 | 432 | @Override 433 | public void onTabReselected(TabView tab, int position) { 434 | } 435 | }); 436 | 437 | setPagerAdapter(adapter, true); 438 | } else { 439 | mViewPager = null; 440 | setPagerAdapter(null, true); 441 | } 442 | } 443 | 444 | private void setPagerAdapter(@Nullable final PagerAdapter adapter, final boolean addObserver) { 445 | if (mPagerAdapter != null && mPagerAdapterObserver != null) { 446 | mPagerAdapter.unregisterDataSetObserver(mPagerAdapterObserver); 447 | } 448 | 449 | mPagerAdapter = adapter; 450 | 451 | if (addObserver && adapter != null) { 452 | if (mPagerAdapterObserver == null) { 453 | mPagerAdapterObserver = new PagerAdapterObserver(); 454 | } 455 | adapter.registerDataSetObserver(mPagerAdapterObserver); 456 | } 457 | 458 | populateFromPagerAdapter(); 459 | } 460 | 461 | private void populateFromPagerAdapter() { 462 | removeAllTabs(); 463 | if (mPagerAdapter != null) { 464 | final int adapterCount = mPagerAdapter.getCount(); 465 | if (mPagerAdapter instanceof TabAdapter) { 466 | setTabAdapter((TabAdapter) mPagerAdapter); 467 | } else { 468 | for (int i = 0; i < adapterCount; i++) { 469 | String title = mPagerAdapter.getPageTitle(i) == null ? "tab" + i : mPagerAdapter.getPageTitle(i).toString(); 470 | addTab(new QTabView(mContext).setTitle( 471 | new QTabView.TabTitle.Builder().setContent(title).build())); 472 | } 473 | } 474 | 475 | // Make sure we reflect the currently set ViewPager item 476 | if (mViewPager != null && adapterCount > 0) { 477 | final int curItem = mViewPager.getCurrentItem(); 478 | if (curItem != getSelectedTabPosition() && curItem < getTabCount()) { 479 | setTabSelected(curItem); 480 | } 481 | } 482 | } else { 483 | removeAllTabs(); 484 | } 485 | } 486 | 487 | private class TabStrip extends LinearLayout { 488 | private float mIndicatorTopY; 489 | private float mIndicatorX; 490 | private float mIndicatorBottomY; 491 | private int mLastWidth; 492 | private Paint mIndicatorPaint; 493 | private RectF mIndicatorRect; 494 | private AnimatorSet mIndicatorAnimatorSet; 495 | 496 | public TabStrip(Context context) { 497 | super(context); 498 | setWillNotDraw(false); 499 | setOrientation(LinearLayout.VERTICAL); 500 | mIndicatorPaint = new Paint(); 501 | mIndicatorPaint.setAntiAlias(true); 502 | mIndicatorGravity = mIndicatorGravity == 0 ? Gravity.LEFT : mIndicatorGravity; 503 | mIndicatorRect = new RectF(); 504 | setIndicatorGravity(); 505 | } 506 | 507 | protected void setIndicatorGravity() { 508 | if (mIndicatorGravity == Gravity.LEFT) { 509 | mIndicatorX = 0; 510 | if (mLastWidth != 0) mIndicatorWidth = mLastWidth; 511 | setPadding(mIndicatorWidth, 0, 0, 0); 512 | } else if (mIndicatorGravity == Gravity.RIGHT) { 513 | if (mLastWidth != 0) mIndicatorWidth = mLastWidth; 514 | setPadding(0, 0, mIndicatorWidth, 0); 515 | } else if (mIndicatorGravity == Gravity.FILL) { 516 | mIndicatorX = 0; 517 | setPadding(0, 0, 0, 0); 518 | } 519 | post(new Runnable() { 520 | @Override 521 | public void run() { 522 | if (mIndicatorGravity == Gravity.RIGHT) { 523 | mIndicatorX = getWidth() - mIndicatorWidth; 524 | } else if (mIndicatorGravity == Gravity.FILL) { 525 | mLastWidth = mIndicatorWidth; 526 | mIndicatorWidth = getWidth(); 527 | } 528 | invalidate(); 529 | } 530 | }); 531 | } 532 | 533 | private void calcIndicatorY(float offset) { 534 | int index = (int) Math.floor(offset); 535 | View childView = getChildAt(index); 536 | if (Math.floor(offset) != getChildCount() - 1 && Math.ceil(offset) != 0) { 537 | View nextView = getChildAt(index + 1); 538 | mIndicatorTopY = childView.getTop() + (nextView.getTop() - childView.getTop()) * (offset - index); 539 | mIndicatorBottomY = childView.getBottom() + (nextView.getBottom() - 540 | childView.getBottom()) * (offset - index); 541 | } else { 542 | mIndicatorTopY = childView.getTop(); 543 | mIndicatorBottomY = childView.getBottom(); 544 | } 545 | } 546 | 547 | protected void updataIndicator() { 548 | moveIndicatorWithAnimator(getSelectedTabPosition()); 549 | } 550 | 551 | protected void moveIndicator(float offset) { 552 | calcIndicatorY(offset); 553 | invalidate(); 554 | } 555 | 556 | /** 557 | * move indicator to a tab location 558 | * 559 | * @param index tab location's index 560 | */ 561 | protected void moveIndicatorWithAnimator(int index) { 562 | final int direction = index - getSelectedTabPosition(); 563 | View childView = getChildAt(index); 564 | final float targetTop = childView.getTop(); 565 | final float targetBottom = childView.getBottom(); 566 | if (mIndicatorTopY == targetTop && mIndicatorBottomY == targetBottom) return; 567 | if (mIndicatorAnimatorSet != null && mIndicatorAnimatorSet.isRunning()) { 568 | mIndicatorAnimatorSet.end(); 569 | } 570 | post(new Runnable() { 571 | @Override 572 | public void run() { 573 | ValueAnimator startAnime = null; 574 | ValueAnimator endAnime = null; 575 | if (direction > 0) { 576 | startAnime = ValueAnimator.ofFloat(mIndicatorBottomY, targetBottom) 577 | .setDuration(100); 578 | startAnime.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 579 | @Override 580 | public void onAnimationUpdate(ValueAnimator animation) { 581 | mIndicatorBottomY = Float.parseFloat(animation.getAnimatedValue().toString()); 582 | invalidate(); 583 | } 584 | }); 585 | endAnime = ValueAnimator.ofFloat(mIndicatorTopY, targetTop).setDuration(100); 586 | endAnime.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 587 | @Override 588 | public void onAnimationUpdate(ValueAnimator animation) { 589 | mIndicatorTopY = Float.parseFloat(animation.getAnimatedValue().toString()); 590 | invalidate(); 591 | } 592 | }); 593 | } else if (direction < 0) { 594 | startAnime = ValueAnimator.ofFloat(mIndicatorTopY, targetTop).setDuration(100); 595 | startAnime.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 596 | @Override 597 | public void onAnimationUpdate(ValueAnimator animation) { 598 | mIndicatorTopY = Float.parseFloat(animation.getAnimatedValue().toString()); 599 | invalidate(); 600 | } 601 | }); 602 | endAnime = ValueAnimator.ofFloat(mIndicatorBottomY, targetBottom).setDuration(100); 603 | endAnime.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 604 | @Override 605 | public void onAnimationUpdate(ValueAnimator animation) { 606 | mIndicatorBottomY = Float.parseFloat(animation.getAnimatedValue().toString()); 607 | invalidate(); 608 | } 609 | }); 610 | } 611 | if (startAnime != null) { 612 | mIndicatorAnimatorSet = new AnimatorSet(); 613 | mIndicatorAnimatorSet.play(endAnime).after(startAnime); 614 | mIndicatorAnimatorSet.start(); 615 | } 616 | } 617 | }); 618 | } 619 | 620 | @Override 621 | protected void onDraw(Canvas canvas) { 622 | super.onDraw(canvas); 623 | mIndicatorPaint.setColor(mColorIndicator); 624 | mIndicatorRect.left = mIndicatorX; 625 | mIndicatorRect.top = mIndicatorTopY; 626 | mIndicatorRect.right = mIndicatorX + mIndicatorWidth; 627 | mIndicatorRect.bottom = mIndicatorBottomY; 628 | if (mIndicatorCorners != 0) { 629 | canvas.drawRoundRect(mIndicatorRect, mIndicatorCorners, mIndicatorCorners, mIndicatorPaint); 630 | } else { 631 | canvas.drawRect(mIndicatorRect, mIndicatorPaint); 632 | } 633 | } 634 | 635 | } 636 | 637 | private class OnTabPageChangeListener implements ViewPager.OnPageChangeListener { 638 | private int mPreviousScrollState; 639 | private int mScrollState; 640 | boolean mUpdataIndicator; 641 | 642 | public OnTabPageChangeListener() { 643 | } 644 | 645 | @Override 646 | public void onPageScrollStateChanged(int state) { 647 | mPreviousScrollState = mScrollState; 648 | mScrollState = state; 649 | mUpdataIndicator = !(mScrollState == SCROLL_STATE_SETTLING 650 | && mPreviousScrollState == SCROLL_STATE_IDLE); 651 | } 652 | 653 | @Override 654 | public void onPageScrolled(int position, float positionOffset, 655 | int positionOffsetPixels) { 656 | if (mUpdataIndicator) { 657 | mTabStrip.moveIndicator(positionOffset + position); 658 | } 659 | } 660 | 661 | @Override 662 | public void onPageSelected(int position) { 663 | if (position != getSelectedTabPosition()) { 664 | setTabSelected(position, !mUpdataIndicator, true); 665 | } 666 | } 667 | } 668 | 669 | private class PagerAdapterObserver extends DataSetObserver { 670 | @Override 671 | public void onChanged() { 672 | populateFromPagerAdapter(); 673 | } 674 | 675 | @Override 676 | public void onInvalidated() { 677 | populateFromPagerAdapter(); 678 | } 679 | } 680 | 681 | public interface OnTabSelectedListener { 682 | 683 | void onTabSelected(TabView tab, int position); 684 | 685 | void onTabReselected(TabView tab, int position); 686 | } 687 | } 688 | -------------------------------------------------------------------------------- /verticaltablayout/src/main/java/q/rorbin/verticaltablayout/adapter/SimpleTabAdapter.java: -------------------------------------------------------------------------------- 1 | package q.rorbin.verticaltablayout.adapter; 2 | 3 | import q.rorbin.verticaltablayout.widget.TabView; 4 | 5 | /** 6 | * Created by chqiu on 2017/1/20. 7 | */ 8 | 9 | public abstract class SimpleTabAdapter implements TabAdapter { 10 | @Override 11 | public abstract int getCount(); 12 | 13 | @Override 14 | public TabView.TabBadge getBadge(int position) { 15 | return null; 16 | } 17 | 18 | @Override 19 | public TabView.TabIcon getIcon(int position) { 20 | return null; 21 | } 22 | 23 | @Override 24 | public TabView.TabTitle getTitle(int position) { 25 | return null; 26 | } 27 | 28 | @Override 29 | public int getBackground(int position) { 30 | return 0; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /verticaltablayout/src/main/java/q/rorbin/verticaltablayout/adapter/TabAdapter.java: -------------------------------------------------------------------------------- 1 | package q.rorbin.verticaltablayout.adapter; 2 | 3 | 4 | 5 | import q.rorbin.verticaltablayout.widget.TabView; 6 | 7 | /** 8 | * @author chqiu 9 | * Email:qstumn@163.com 10 | */ 11 | public interface TabAdapter { 12 | int getCount(); 13 | 14 | TabView.TabBadge getBadge(int position); 15 | 16 | TabView.TabIcon getIcon(int position); 17 | 18 | TabView.TabTitle getTitle(int position); 19 | 20 | int getBackground(int position); 21 | } 22 | -------------------------------------------------------------------------------- /verticaltablayout/src/main/java/q/rorbin/verticaltablayout/util/DisplayUtil.java: -------------------------------------------------------------------------------- 1 | package q.rorbin.verticaltablayout.util; 2 | 3 | import android.content.Context; 4 | 5 | /** 6 | * Created by chqiu on 2017/1/20. 7 | */ 8 | 9 | public class DisplayUtil { 10 | public static int dp2px(Context context, float dp) { 11 | final float scale = context.getResources().getDisplayMetrics().density; 12 | return (int) (dp * scale + 0.5f); 13 | } 14 | 15 | public static int px2dp(Context context, float pxValue) { 16 | final float scale = context.getResources().getDisplayMetrics().density; 17 | return (int) (pxValue / scale + 0.5f); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /verticaltablayout/src/main/java/q/rorbin/verticaltablayout/util/TabFragmentManager.java: -------------------------------------------------------------------------------- 1 | package q.rorbin.verticaltablayout.util; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | import android.support.v4.app.FragmentTransaction; 6 | 7 | import java.util.List; 8 | 9 | import q.rorbin.verticaltablayout.VerticalTabLayout; 10 | import q.rorbin.verticaltablayout.widget.TabView; 11 | 12 | 13 | 14 | /** 15 | * Created by chqiu on 2017/1/16. 16 | */ 17 | 18 | public class TabFragmentManager { 19 | private FragmentManager mManager; 20 | private int mContainerResid; 21 | private List mFragments; 22 | private VerticalTabLayout mTabLayout; 23 | private VerticalTabLayout.OnTabSelectedListener mListener; 24 | 25 | public TabFragmentManager(FragmentManager manager, List fragments, VerticalTabLayout tabLayout) { 26 | this.mManager = manager; 27 | this.mFragments = fragments; 28 | this.mTabLayout = tabLayout; 29 | mListener = new OnFragmentTabSelectedListener(); 30 | mTabLayout.addOnTabSelectedListener(mListener); 31 | } 32 | 33 | public TabFragmentManager(FragmentManager manager, int containerResid, List fragments, VerticalTabLayout tabLayout) { 34 | this(manager, fragments, tabLayout); 35 | this.mContainerResid = containerResid; 36 | changeFragment(); 37 | } 38 | 39 | public void changeFragment() { 40 | FragmentTransaction ft = mManager.beginTransaction(); 41 | int position = mTabLayout.getSelectedTabPosition(); 42 | List addedFragments = mManager.getFragments(); 43 | for (int i = 0; i < mFragments.size(); i++) { 44 | Fragment fragment = mFragments.get(i); 45 | if ((addedFragments == null || !addedFragments.contains(fragment)) && mContainerResid != 0) { 46 | ft.add(mContainerResid, fragment); 47 | } 48 | if ((mFragments.size() > position && i == position) 49 | || (mFragments.size() <= position && i == mFragments.size() - 1)) { 50 | ft.show(fragment); 51 | } else { 52 | ft.hide(fragment); 53 | } 54 | } 55 | ft.commit(); 56 | mManager.executePendingTransactions(); 57 | } 58 | 59 | public void detach() { 60 | FragmentTransaction ft = mManager.beginTransaction(); 61 | for (Fragment fragment : mFragments) { 62 | ft.remove(fragment); 63 | } 64 | ft.commit(); 65 | mManager.executePendingTransactions(); 66 | mManager = null; 67 | mFragments = null; 68 | mTabLayout.removeOnTabSelectedListener(mListener); 69 | mListener = null; 70 | mTabLayout = null; 71 | } 72 | 73 | 74 | private class OnFragmentTabSelectedListener implements VerticalTabLayout.OnTabSelectedListener { 75 | 76 | @Override 77 | public void onTabSelected(TabView tab, int position) { 78 | changeFragment(); 79 | } 80 | 81 | @Override 82 | public void onTabReselected(TabView tab, int position) { 83 | 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /verticaltablayout/src/main/java/q/rorbin/verticaltablayout/widget/ITabView.java: -------------------------------------------------------------------------------- 1 | package q.rorbin.verticaltablayout.widget; 2 | 3 | import android.graphics.Color; 4 | import android.graphics.drawable.Drawable; 5 | import android.view.Gravity; 6 | import android.view.View; 7 | 8 | import q.rorbin.badgeview.Badge; 9 | 10 | /** 11 | * @author chqiu 12 | * Email:qstumn@163.com 13 | */ 14 | 15 | public interface ITabView { 16 | 17 | ITabView setBadge(TabBadge badge); 18 | 19 | ITabView setIcon(TabIcon icon); 20 | 21 | ITabView setTitle(TabTitle title); 22 | 23 | ITabView setBackground(int resid); 24 | 25 | TabBadge getBadge(); 26 | 27 | TabIcon getIcon(); 28 | 29 | TabTitle getTitle(); 30 | 31 | View getTabView(); 32 | 33 | class TabIcon { 34 | 35 | private Builder mBuilder; 36 | 37 | private TabIcon(Builder mBuilder) { 38 | this.mBuilder = mBuilder; 39 | } 40 | 41 | public int getSelectedIcon() { 42 | return mBuilder.mSelectedIcon; 43 | } 44 | 45 | public int getNormalIcon() { 46 | return mBuilder.mNormalIcon; 47 | } 48 | 49 | public int getIconGravity() { 50 | return mBuilder.mIconGravity; 51 | } 52 | 53 | public int getIconWidth() { 54 | return mBuilder.mIconWidth; 55 | } 56 | 57 | public int getIconHeight() { 58 | return mBuilder.mIconHeight; 59 | } 60 | 61 | public int getMargin() { 62 | return mBuilder.mMargin; 63 | } 64 | 65 | public static class Builder { 66 | private int mSelectedIcon; 67 | private int mNormalIcon; 68 | private int mIconGravity; 69 | private int mIconWidth; 70 | private int mIconHeight; 71 | private int mMargin; 72 | 73 | public Builder() { 74 | mSelectedIcon = 0; 75 | mNormalIcon = 0; 76 | mIconWidth = -1; 77 | mIconHeight = -1; 78 | mIconGravity = Gravity.START; 79 | mMargin = 0; 80 | } 81 | 82 | public Builder setIcon(int selectIconResId, int normalIconResId) { 83 | mSelectedIcon = selectIconResId; 84 | mNormalIcon = normalIconResId; 85 | return this; 86 | } 87 | 88 | public Builder setIconSize(int width, int height) { 89 | mIconWidth = width; 90 | mIconHeight = height; 91 | return this; 92 | } 93 | 94 | public Builder setIconGravity(int gravity) { 95 | if (gravity != Gravity.START && gravity != Gravity.END 96 | & gravity != Gravity.TOP & gravity != Gravity.BOTTOM) { 97 | throw new IllegalStateException("iconGravity only support Gravity.START " + 98 | "or Gravity.END or Gravity.TOP or Gravity.BOTTOM"); 99 | } 100 | mIconGravity = gravity; 101 | return this; 102 | } 103 | 104 | public Builder setIconMargin(int margin) { 105 | mMargin = margin; 106 | return this; 107 | } 108 | 109 | public TabIcon build() { 110 | return new TabIcon(this); 111 | } 112 | } 113 | } 114 | 115 | class TabTitle { 116 | private Builder mBuilder; 117 | 118 | private TabTitle(Builder mBuilder) { 119 | this.mBuilder = mBuilder; 120 | } 121 | 122 | public int getColorSelected() { 123 | return mBuilder.mColorSelected; 124 | } 125 | 126 | public int getColorNormal() { 127 | return mBuilder.mColorNormal; 128 | } 129 | 130 | public int getTitleTextSize() { 131 | return mBuilder.mTitleTextSize; 132 | } 133 | 134 | public String getContent() { 135 | return mBuilder.mContent; 136 | } 137 | 138 | public static class Builder { 139 | private int mColorSelected; 140 | private int mColorNormal; 141 | private int mTitleTextSize; 142 | private String mContent; 143 | 144 | public Builder() { 145 | this.mColorSelected = 0xFFFF4081; 146 | this.mColorNormal = 0xFF757575; 147 | this.mTitleTextSize = 16; 148 | this.mContent = ""; 149 | } 150 | 151 | public Builder setTextColor(int colorSelected, int colorNormal) { 152 | mColorSelected = colorSelected; 153 | mColorNormal = colorNormal; 154 | return this; 155 | } 156 | 157 | public Builder setTextSize(int sizeSp) { 158 | mTitleTextSize = sizeSp; 159 | return this; 160 | } 161 | 162 | public Builder setContent(String content) { 163 | mContent = content; 164 | return this; 165 | } 166 | 167 | public TabTitle build() { 168 | return new TabTitle(this); 169 | } 170 | } 171 | } 172 | 173 | class TabBadge { 174 | private Builder mBuilder; 175 | 176 | private TabBadge(Builder mBuilder) { 177 | this.mBuilder = mBuilder; 178 | } 179 | 180 | public int getBackgroundColor() { 181 | return mBuilder.colorBackground; 182 | } 183 | 184 | public int getBadgeTextColor() { 185 | return mBuilder.colorBadgeText; 186 | } 187 | 188 | public float getBadgeTextSize() { 189 | return mBuilder.badgeTextSize; 190 | } 191 | 192 | public float getBadgePadding() { 193 | return mBuilder.badgePadding; 194 | } 195 | 196 | public int getBadgeNumber() { 197 | return mBuilder.badgeNumber; 198 | } 199 | 200 | public String getBadgeText() { 201 | return mBuilder.badgeText; 202 | } 203 | 204 | public int getBadgeGravity() { 205 | return mBuilder.badgeGravity; 206 | } 207 | 208 | public int getGravityOffsetX() { 209 | return mBuilder.gravityOffsetX; 210 | } 211 | 212 | public int getGravityOffsetY() { 213 | return mBuilder.gravityOffsetY; 214 | } 215 | 216 | public boolean isExactMode() { 217 | return mBuilder.exactMode; 218 | } 219 | 220 | public boolean isShowShadow() { 221 | return mBuilder.showShadow; 222 | } 223 | 224 | public Drawable getDrawableBackground() { 225 | return mBuilder.drawableBackground; 226 | } 227 | 228 | public int getStrokeColor() { 229 | return mBuilder.colorStroke; 230 | } 231 | 232 | public boolean isDrawableBackgroundClip() { 233 | return mBuilder.drawableBackgroundClip; 234 | } 235 | 236 | public float getStrokeWidth() { 237 | return mBuilder.strokeWidth; 238 | } 239 | 240 | public Badge.OnDragStateChangedListener getOnDragStateChangedListener() { 241 | return mBuilder.dragStateChangedListener; 242 | } 243 | 244 | public static class Builder { 245 | private int colorBackground; 246 | private int colorBadgeText; 247 | private int colorStroke; 248 | private Drawable drawableBackground; 249 | private boolean drawableBackgroundClip; 250 | private float strokeWidth; 251 | private float badgeTextSize; 252 | private float badgePadding; 253 | private int badgeNumber; 254 | private String badgeText; 255 | private int badgeGravity; 256 | private int gravityOffsetX; 257 | private int gravityOffsetY; 258 | private boolean exactMode; 259 | private boolean showShadow; 260 | private Badge.OnDragStateChangedListener dragStateChangedListener; 261 | 262 | public Builder() { 263 | colorBackground = 0xFFE84E40; 264 | colorBadgeText = 0xFFFFFFFF; 265 | colorStroke = Color.TRANSPARENT; 266 | drawableBackground = null; 267 | drawableBackgroundClip = false; 268 | strokeWidth = 0; 269 | badgeTextSize = 11; 270 | badgePadding = 5; 271 | badgeNumber = 0; 272 | badgeText = null; 273 | badgeGravity = Gravity.END | Gravity.TOP; 274 | gravityOffsetX = 1; 275 | gravityOffsetY = 1; 276 | exactMode = false; 277 | showShadow = true; 278 | } 279 | 280 | public TabBadge build() { 281 | return new TabBadge(this); 282 | } 283 | 284 | public Builder stroke(int color, int strokeWidth) { 285 | this.colorStroke = color; 286 | this.strokeWidth = strokeWidth; 287 | return this; 288 | } 289 | 290 | public Builder setDrawableBackground(Drawable drawableBackground, boolean clip) { 291 | this.drawableBackground = drawableBackground; 292 | this.drawableBackgroundClip = clip; 293 | return this; 294 | } 295 | 296 | public Builder setShowShadow(boolean showShadow) { 297 | this.showShadow = showShadow; 298 | return this; 299 | } 300 | 301 | public Builder setOnDragStateChangedListener(Badge.OnDragStateChangedListener dragStateChangedListener) { 302 | this.dragStateChangedListener = dragStateChangedListener; 303 | return this; 304 | } 305 | 306 | public Builder setExactMode(boolean exactMode) { 307 | this.exactMode = exactMode; 308 | return this; 309 | } 310 | 311 | public Builder setBackgroundColor(int colorBackground) { 312 | this.colorBackground = colorBackground; 313 | return this; 314 | } 315 | 316 | public Builder setBadgePadding(float dpValue) { 317 | this.badgePadding = dpValue; 318 | return this; 319 | } 320 | 321 | public Builder setBadgeNumber(int badgeNumber) { 322 | this.badgeNumber = badgeNumber; 323 | this.badgeText = null; 324 | return this; 325 | } 326 | 327 | public Builder setBadgeGravity(int badgeGravity) { 328 | this.badgeGravity = badgeGravity; 329 | return this; 330 | } 331 | 332 | public Builder setBadgeTextColor(int colorBadgeText) { 333 | this.colorBadgeText = colorBadgeText; 334 | return this; 335 | } 336 | 337 | public Builder setBadgeTextSize(float badgeTextSize) { 338 | this.badgeTextSize = badgeTextSize; 339 | return this; 340 | } 341 | 342 | public Builder setBadgeText(String badgeText) { 343 | this.badgeText = badgeText; 344 | this.badgeNumber = 0; 345 | return this; 346 | } 347 | 348 | public Builder setGravityOffset(int offsetX, int offsetY) { 349 | this.gravityOffsetX = offsetX; 350 | this.gravityOffsetY = offsetY; 351 | return this; 352 | } 353 | } 354 | } 355 | } 356 | -------------------------------------------------------------------------------- /verticaltablayout/src/main/java/q/rorbin/verticaltablayout/widget/QTabView.java: -------------------------------------------------------------------------------- 1 | package q.rorbin.verticaltablayout.widget; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Color; 6 | import android.graphics.drawable.Drawable; 7 | import android.os.Build; 8 | import android.support.annotation.Px; 9 | import android.support.annotation.RequiresApi; 10 | import android.text.TextUtils; 11 | import android.util.Log; 12 | import android.view.Gravity; 13 | import android.view.View; 14 | import android.widget.Checkable; 15 | import android.widget.ImageView; 16 | import android.widget.LinearLayout; 17 | import android.widget.TextView; 18 | 19 | import q.rorbin.badgeview.Badge; 20 | import q.rorbin.badgeview.QBadgeView; 21 | import q.rorbin.verticaltablayout.util.DisplayUtil; 22 | 23 | import static android.R.attr.checked; 24 | import static android.R.attr.gravity; 25 | 26 | /** 27 | * @author chqiu 28 | * Email:qstumn@163.com 29 | */ 30 | public class QTabView extends TabView { 31 | private Context mContext; 32 | private TextView mTitle; 33 | private Badge mBadgeView; 34 | private TabIcon mTabIcon; 35 | private TabTitle mTabTitle; 36 | private TabBadge mTabBadge; 37 | private boolean mChecked; 38 | private Drawable mDefaultBackground; 39 | 40 | 41 | public QTabView(Context context) { 42 | super(context); 43 | mContext = context; 44 | mTabIcon = new TabIcon.Builder().build(); 45 | mTabTitle = new TabTitle.Builder().build(); 46 | mTabBadge = new TabBadge.Builder().build(); 47 | initView(); 48 | int[] attrs; 49 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 50 | attrs = new int[]{android.R.attr.selectableItemBackgroundBorderless}; 51 | } else { 52 | attrs = new int[]{android.R.attr.selectableItemBackground}; 53 | } 54 | TypedArray a = mContext.getTheme().obtainStyledAttributes(attrs); 55 | mDefaultBackground = a.getDrawable(0); 56 | a.recycle(); 57 | setDefaultBackground(); 58 | } 59 | 60 | private void initView() { 61 | setMinimumHeight(q.rorbin.badgeview.DisplayUtil.dp2px(mContext,25)); 62 | if (mTitle == null) { 63 | mTitle = new TextView(mContext); 64 | LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); 65 | params.gravity = Gravity.CENTER; 66 | mTitle.setLayoutParams(params); 67 | this.addView(mTitle); 68 | } 69 | initTitleView(); 70 | initIconView(); 71 | initBadge(); 72 | } 73 | 74 | @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) 75 | @Override 76 | public void setPaddingRelative(@Px int start, @Px int top, @Px int end, @Px int bottom) { 77 | mTitle.setPaddingRelative(start, top, end, bottom); 78 | } 79 | 80 | @Override 81 | public void setPadding(@Px int left, @Px int top, @Px int right, @Px int bottom) { 82 | mTitle.setPadding(left, top, right, bottom); 83 | } 84 | 85 | private void initBadge() { 86 | mBadgeView = TabBadgeView.bindTab(this); 87 | if (mTabBadge.getBackgroundColor() != 0xFFE84E40) { 88 | mBadgeView.setBadgeBackgroundColor(mTabBadge.getBackgroundColor()); 89 | } 90 | if (mTabBadge.getBadgeTextColor() != 0xFFFFFFFF) { 91 | mBadgeView.setBadgeTextColor(mTabBadge.getBadgeTextColor()); 92 | } 93 | if (mTabBadge.getStrokeColor() != Color.TRANSPARENT || mTabBadge.getStrokeWidth() != 0) { 94 | mBadgeView.stroke(mTabBadge.getStrokeColor(), mTabBadge.getStrokeWidth(), true); 95 | } 96 | if (mTabBadge.getDrawableBackground() != null || mTabBadge.isDrawableBackgroundClip()) { 97 | mBadgeView.setBadgeBackground(mTabBadge.getDrawableBackground(), mTabBadge.isDrawableBackgroundClip()); 98 | } 99 | if (mTabBadge.getBadgeTextSize() != 11) { 100 | mBadgeView.setBadgeTextSize(mTabBadge.getBadgeTextSize(), true); 101 | } 102 | if (mTabBadge.getBadgePadding() != 5) { 103 | mBadgeView.setBadgePadding(mTabBadge.getBadgePadding(), true); 104 | } 105 | if (mTabBadge.getBadgeNumber() != 0) { 106 | mBadgeView.setBadgeNumber(mTabBadge.getBadgeNumber()); 107 | } 108 | if (mTabBadge.getBadgeText() != null) { 109 | mBadgeView.setBadgeText(mTabBadge.getBadgeText()); 110 | } 111 | if (mTabBadge.getBadgeGravity() != (Gravity.END | Gravity.TOP)) { 112 | mBadgeView.setBadgeGravity(mTabBadge.getBadgeGravity()); 113 | } 114 | if (mTabBadge.getGravityOffsetX() != 5 || mTabBadge.getGravityOffsetY() != 5) { 115 | mBadgeView.setGravityOffset(mTabBadge.getGravityOffsetX(), mTabBadge.getGravityOffsetY(), true); 116 | } 117 | if (mTabBadge.isExactMode()) { 118 | mBadgeView.setExactMode(mTabBadge.isExactMode()); 119 | } 120 | if (!mTabBadge.isShowShadow()) { 121 | mBadgeView.setShowShadow(mTabBadge.isShowShadow()); 122 | } 123 | if (mTabBadge.getOnDragStateChangedListener() != null) { 124 | mBadgeView.setOnDragStateChangedListener(mTabBadge.getOnDragStateChangedListener()); 125 | } 126 | } 127 | 128 | private void initTitleView() { 129 | mTitle.setTextColor(isChecked() ? mTabTitle.getColorSelected() : mTabTitle.getColorNormal()); 130 | mTitle.setTextSize(mTabTitle.getTitleTextSize()); 131 | mTitle.setText(mTabTitle.getContent()); 132 | mTitle.setGravity(Gravity.CENTER); 133 | mTitle.setEllipsize(TextUtils.TruncateAt.END); 134 | refreshDrawablePadding(); 135 | } 136 | 137 | private void initIconView() { 138 | int iconResid = mChecked ? mTabIcon.getSelectedIcon() : mTabIcon.getNormalIcon(); 139 | Drawable drawable = null; 140 | if (iconResid != 0) { 141 | drawable = mContext.getResources().getDrawable(iconResid); 142 | int r = mTabIcon.getIconWidth() != -1 ? mTabIcon.getIconWidth() : drawable.getIntrinsicWidth(); 143 | int b = mTabIcon.getIconHeight() != -1 ? mTabIcon.getIconHeight() : drawable.getIntrinsicHeight(); 144 | drawable.setBounds(0, 0, r, b); 145 | } 146 | switch (mTabIcon.getIconGravity()) { 147 | case Gravity.START: 148 | mTitle.setCompoundDrawables(drawable, null, null, null); 149 | break; 150 | case Gravity.TOP: 151 | mTitle.setCompoundDrawables(null, drawable, null, null); 152 | break; 153 | case Gravity.END: 154 | mTitle.setCompoundDrawables(null, null, drawable, null); 155 | break; 156 | case Gravity.BOTTOM: 157 | mTitle.setCompoundDrawables(null, null, null, drawable); 158 | break; 159 | } 160 | refreshDrawablePadding(); 161 | } 162 | 163 | private void refreshDrawablePadding() { 164 | int iconResid = mChecked ? mTabIcon.getSelectedIcon() : mTabIcon.getNormalIcon(); 165 | if (iconResid != 0) { 166 | if (!TextUtils.isEmpty(mTabTitle.getContent()) && mTitle.getCompoundDrawablePadding() != mTabIcon.getMargin()) { 167 | mTitle.setCompoundDrawablePadding(mTabIcon.getMargin()); 168 | } else if (TextUtils.isEmpty(mTabTitle.getContent())) { 169 | mTitle.setCompoundDrawablePadding(0); 170 | } 171 | } else { 172 | mTitle.setCompoundDrawablePadding(0); 173 | } 174 | } 175 | 176 | @Override 177 | public QTabView setBadge(TabBadge badge) { 178 | if (badge != null) { 179 | mTabBadge = badge; 180 | } 181 | initBadge(); 182 | return this; 183 | } 184 | 185 | @Override 186 | public QTabView setIcon(TabIcon icon) { 187 | if (icon != null) { 188 | mTabIcon = icon; 189 | } 190 | initIconView(); 191 | return this; 192 | } 193 | 194 | @Override 195 | public QTabView setTitle(TabTitle title) { 196 | if (title != null) { 197 | mTabTitle = title; 198 | } 199 | initTitleView(); 200 | return this; 201 | } 202 | 203 | /** 204 | * @param resId The Drawable res to use as the background, if less than 0 will to remove the 205 | * background 206 | */ 207 | @Override 208 | public QTabView setBackground(int resId) { 209 | if (resId == 0) { 210 | setDefaultBackground(); 211 | } else if (resId <= 0) { 212 | setBackground(null); 213 | } else { 214 | super.setBackgroundResource(resId); 215 | } 216 | return this; 217 | } 218 | 219 | @Override 220 | public TabBadge getBadge() { 221 | return mTabBadge; 222 | } 223 | 224 | @Override 225 | public TabIcon getIcon() { 226 | return mTabIcon; 227 | } 228 | 229 | @Override 230 | public TabTitle getTitle() { 231 | return mTabTitle; 232 | } 233 | 234 | @Override 235 | @Deprecated 236 | public ImageView getIconView() { 237 | return null; 238 | } 239 | 240 | @Override 241 | public TextView getTitleView() { 242 | return mTitle; 243 | } 244 | 245 | @Override 246 | public Badge getBadgeView() { 247 | return mBadgeView; 248 | } 249 | 250 | @Override 251 | public void setBackground(Drawable background) { 252 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 253 | super.setBackground(background); 254 | } else { 255 | super.setBackgroundDrawable(background); 256 | } 257 | } 258 | 259 | @Override 260 | public void setBackgroundResource(int resid) { 261 | setBackground(resid); 262 | } 263 | 264 | private void setDefaultBackground() { 265 | if (getBackground() != mDefaultBackground) { 266 | setBackground(mDefaultBackground); 267 | } 268 | } 269 | 270 | @Override 271 | public void setChecked(boolean checked) { 272 | mChecked = checked; 273 | setSelected(checked); 274 | refreshDrawableState(); 275 | mTitle.setTextColor(checked ? mTabTitle.getColorSelected() : mTabTitle.getColorNormal()); 276 | initIconView(); 277 | } 278 | 279 | @Override 280 | public boolean isChecked() { 281 | return mChecked; 282 | } 283 | 284 | @Override 285 | public void toggle() { 286 | setChecked(!mChecked); 287 | } 288 | } -------------------------------------------------------------------------------- /verticaltablayout/src/main/java/q/rorbin/verticaltablayout/widget/TabBadgeView.java: -------------------------------------------------------------------------------- 1 | package q.rorbin.verticaltablayout.widget; 2 | 3 | import android.content.Context; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | import android.widget.FrameLayout; 7 | 8 | import q.rorbin.badgeview.QBadgeView; 9 | 10 | 11 | /** 12 | * Created by chqiu on 2017/2/10. 13 | */ 14 | 15 | public class TabBadgeView extends QBadgeView { 16 | private TabBadgeView(Context context) { 17 | super(context); 18 | } 19 | 20 | public static TabBadgeView bindTab(TabView tab) { 21 | TabBadgeView badge = null; 22 | for (int i = 0; i < tab.getChildCount(); i++) { 23 | View child = tab.getChildAt(i); 24 | if (child != null && child instanceof TabBadgeView) { 25 | badge = (TabBadgeView) child; 26 | break; 27 | } 28 | } 29 | if (badge == null) { 30 | badge = new TabBadgeView(tab.getContext()); 31 | tab.addView(badge, new TabView.LayoutParams(TabView.LayoutParams.MATCH_PARENT, TabView.LayoutParams.MATCH_PARENT)); 32 | } 33 | badge.mTargetView = tab; 34 | return badge; 35 | } 36 | 37 | @Override 38 | protected void screenFromWindow(boolean screen) { 39 | if (getParent() != null) { 40 | ((ViewGroup) getParent()).removeView(this); 41 | } 42 | if (screen) { 43 | mActivityRoot.addView(this, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, 44 | FrameLayout.LayoutParams.MATCH_PARENT)); 45 | } else { 46 | if (mTargetView instanceof TabView) { 47 | ((TabView) mTargetView).addView(this, 48 | new TabView.LayoutParams(TabView.LayoutParams.MATCH_PARENT, 49 | TabView.LayoutParams.MATCH_PARENT)); 50 | } else { 51 | bindTarget(mTargetView); 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /verticaltablayout/src/main/java/q/rorbin/verticaltablayout/widget/TabView.java: -------------------------------------------------------------------------------- 1 | package q.rorbin.verticaltablayout.widget; 2 | 3 | import android.content.Context; 4 | import android.graphics.Color; 5 | import android.graphics.drawable.Drawable; 6 | import android.view.Gravity; 7 | import android.view.View; 8 | import android.widget.Checkable; 9 | import android.widget.FrameLayout; 10 | import android.widget.ImageView; 11 | import android.widget.TextView; 12 | 13 | import q.rorbin.badgeview.Badge; 14 | 15 | import static android.R.attr.strokeWidth; 16 | 17 | /** 18 | * @author chqiu 19 | * Email:qstumn@163.com 20 | */ 21 | public abstract class TabView extends FrameLayout implements Checkable, ITabView { 22 | 23 | public TabView(Context context) { 24 | super(context); 25 | } 26 | 27 | @Override 28 | public TabView getTabView() { 29 | return this; 30 | } 31 | 32 | @Deprecated 33 | public abstract ImageView getIconView(); 34 | 35 | public abstract TextView getTitleView(); 36 | 37 | public abstract Badge getBadgeView(); 38 | } 39 | -------------------------------------------------------------------------------- /verticaltablayout/src/main/res/drawable-hdpi/man_01_none.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qstumn/VerticalTabLayout/7588fc6766c097132aadcf37940aaea59e9f2e8e/verticaltablayout/src/main/res/drawable-hdpi/man_01_none.png -------------------------------------------------------------------------------- /verticaltablayout/src/main/res/drawable-hdpi/man_01_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qstumn/VerticalTabLayout/7588fc6766c097132aadcf37940aaea59e9f2e8e/verticaltablayout/src/main/res/drawable-hdpi/man_01_pressed.png -------------------------------------------------------------------------------- /verticaltablayout/src/main/res/drawable-hdpi/man_02_none.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qstumn/VerticalTabLayout/7588fc6766c097132aadcf37940aaea59e9f2e8e/verticaltablayout/src/main/res/drawable-hdpi/man_02_none.png -------------------------------------------------------------------------------- /verticaltablayout/src/main/res/drawable-hdpi/man_02_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qstumn/VerticalTabLayout/7588fc6766c097132aadcf37940aaea59e9f2e8e/verticaltablayout/src/main/res/drawable-hdpi/man_02_pressed.png -------------------------------------------------------------------------------- /verticaltablayout/src/main/res/drawable-hdpi/man_03_none.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qstumn/VerticalTabLayout/7588fc6766c097132aadcf37940aaea59e9f2e8e/verticaltablayout/src/main/res/drawable-hdpi/man_03_none.png -------------------------------------------------------------------------------- /verticaltablayout/src/main/res/drawable-hdpi/man_03_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qstumn/VerticalTabLayout/7588fc6766c097132aadcf37940aaea59e9f2e8e/verticaltablayout/src/main/res/drawable-hdpi/man_03_pressed.png -------------------------------------------------------------------------------- /verticaltablayout/src/main/res/drawable-hdpi/man_04_none.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qstumn/VerticalTabLayout/7588fc6766c097132aadcf37940aaea59e9f2e8e/verticaltablayout/src/main/res/drawable-hdpi/man_04_none.png -------------------------------------------------------------------------------- /verticaltablayout/src/main/res/drawable-hdpi/man_04_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qstumn/VerticalTabLayout/7588fc6766c097132aadcf37940aaea59e9f2e8e/verticaltablayout/src/main/res/drawable-hdpi/man_04_pressed.png -------------------------------------------------------------------------------- /verticaltablayout/src/main/res/layout/item_qtabview.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /verticaltablayout/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 23 | 24 | -------------------------------------------------------------------------------- /verticaltablayout/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /verticaltablayout/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | VerticalTabLayout 3 | 4 | -------------------------------------------------------------------------------- /verticaltablayout/src/test/java/q/rorbin/verticaltablayout/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package q.rorbin.verticaltablayout; 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 | } -------------------------------------------------------------------------------- /verticaltablayoutdemo/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /verticaltablayoutdemo/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion '25.0.0' 6 | 7 | defaultConfig { 8 | applicationId "q.rorbin.verticaltablayoutdemo" 9 | minSdkVersion 14 10 | targetSdkVersion 25 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:25.2.0' 26 | compile project(':verticaltablayout') 27 | // compile 'q.rorbin:VerticalTabLayout:1.2.1' 28 | } 29 | -------------------------------------------------------------------------------- /verticaltablayoutdemo/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 E:\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 | -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/androidTest/java/q/rorbin/verticaltablayoutdemo/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package q.rorbin.verticaltablayoutdemo; 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 | } -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/main/java/q/rorbin/verticaltablayoutdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package q.rorbin.verticaltablayoutdemo; 2 | 3 | import android.graphics.Color; 4 | import android.support.v4.view.PagerAdapter; 5 | import android.support.v4.view.ViewPager; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.os.Bundle; 8 | import android.view.Gravity; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.view.WindowManager; 12 | import android.widget.TextView; 13 | 14 | import java.util.ArrayList; 15 | import java.util.Collections; 16 | import java.util.List; 17 | 18 | import q.rorbin.badgeview.Badge; 19 | import q.rorbin.badgeview.DisplayUtil; 20 | import q.rorbin.verticaltablayout.adapter.TabAdapter; 21 | import q.rorbin.verticaltablayout.VerticalTabLayout; 22 | import q.rorbin.verticaltablayout.widget.ITabView; 23 | import q.rorbin.verticaltablayout.widget.TabView; 24 | 25 | public class MainActivity extends AppCompatActivity { 26 | ViewPager viewpager; 27 | 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_main); 33 | viewpager = (ViewPager) findViewById(R.id.viewpager); 34 | viewpager.setAdapter(new MyPagerAdapter()); 35 | initTab0(); 36 | initTab1(); 37 | initTab2(); 38 | initTab3(); 39 | } 40 | 41 | private void initTab0() { 42 | final VerticalTabLayout tablayout = (VerticalTabLayout) findViewById(R.id.tablayout0); 43 | tablayout.setupWithViewPager(viewpager); 44 | tablayout.setTabBadge(7, 32); 45 | tablayout.setTabBadge(2, -1); 46 | tablayout.setTabBadge(3, -1); 47 | tablayout.setTabBadge(4, -1); 48 | } 49 | 50 | private void initTab1() { 51 | VerticalTabLayout tablayout = (VerticalTabLayout) findViewById(R.id.tablayout1); 52 | tablayout.setupWithViewPager(viewpager); 53 | } 54 | 55 | private void initTab2() { 56 | VerticalTabLayout tablayout = (VerticalTabLayout) findViewById(R.id.tablayout2); 57 | tablayout.setupWithViewPager(viewpager); 58 | tablayout.setTabBadge(2, -1); 59 | tablayout.setTabBadge(8, -1); 60 | tablayout.getTabAt(3).setBadge(new TabView.TabBadge.Builder().setBadgeGravity(Gravity.START | Gravity.TOP) 61 | .setBadgeNumber(999) 62 | .setOnDragStateChangedListener(new Badge.OnDragStateChangedListener() { 63 | @Override 64 | public void onDragStateChanged(int dragState, Badge badge, View targetView) { 65 | if (dragState == STATE_SUCCEED) { 66 | badge.setBadgeNumber(-1).stroke(0xFFFFFFFF,1,true); 67 | } 68 | } 69 | }).build()); 70 | } 71 | 72 | private void initTab3() { 73 | VerticalTabLayout tablayout = (VerticalTabLayout) findViewById(R.id.tablayout); 74 | tablayout.setTabAdapter(new MyTabAdapter()); 75 | } 76 | 77 | private class MyTabAdapter implements TabAdapter { 78 | 79 | List menus; 80 | 81 | public MyTabAdapter() { 82 | menus = new ArrayList<>(); 83 | Collections.addAll(menus, new MenuBean(R.drawable.man_01_pressed, R.drawable.man_01_none, "汇总") 84 | , new MenuBean(R.drawable.man_02_pressed, R.drawable.man_02_none, "图表") 85 | , new MenuBean(R.drawable.man_03_pressed, R.drawable.man_03_none, "收藏") 86 | , new MenuBean(R.drawable.man_04_pressed, R.drawable.man_04_none, "竞拍")); 87 | } 88 | 89 | @Override 90 | public int getCount() { 91 | return menus.size(); 92 | } 93 | 94 | @Override 95 | public TabView.TabBadge getBadge(int position) { 96 | return new TabView.TabBadge.Builder().setBadgeNumber(999).setBackgroundColor(0xff2faae5) 97 | .setOnDragStateChangedListener(new Badge.OnDragStateChangedListener() { 98 | @Override 99 | public void onDragStateChanged(int dragState, Badge badge, View targetView) { 100 | } 101 | }).build(); 102 | } 103 | 104 | @Override 105 | public TabView.TabIcon getIcon(int position) { 106 | MenuBean menu = menus.get(position); 107 | return new TabView.TabIcon.Builder() 108 | .setIcon(menu.mSelectIcon, menu.mNormalIcon) 109 | .setIconGravity(Gravity.START) 110 | .setIconMargin(dp2px(5)) 111 | .setIconSize(dp2px(20), dp2px(20)) 112 | .build(); 113 | } 114 | 115 | @Override 116 | public TabView.TabTitle getTitle(int position) { 117 | MenuBean menu = menus.get(position); 118 | return new TabView.TabTitle.Builder() 119 | .setContent(menu.mTitle) 120 | .setTextColor(0xFF36BC9B, 0xFF757575) 121 | .build(); 122 | } 123 | 124 | @Override 125 | public int getBackground(int position) { 126 | return -1; 127 | } 128 | 129 | } 130 | 131 | private class MyPagerAdapter extends PagerAdapter implements TabAdapter { 132 | List titles; 133 | 134 | public MyPagerAdapter() { 135 | titles = new ArrayList<>(); 136 | Collections.addAll(titles, "Android", "IOS", "Web", "JAVA", "C++", 137 | ".NET", "JavaScript", "Swift", "PHP", "Python", "C#", "Groovy", "SQL", "Ruby"); 138 | } 139 | 140 | @Override 141 | public int getCount() { 142 | return titles.size(); 143 | } 144 | 145 | @Override 146 | public TabView.TabBadge getBadge(int position) { 147 | if (position == 5) return new TabView.TabBadge.Builder().setBadgeNumber(666) 148 | .setExactMode(true) 149 | .setOnDragStateChangedListener(new Badge.OnDragStateChangedListener() { 150 | @Override 151 | public void onDragStateChanged(int dragState, Badge badge, View targetView) { 152 | } 153 | }).build(); 154 | return null; 155 | } 156 | 157 | @Override 158 | public TabView.TabIcon getIcon(int position) { 159 | return null; 160 | } 161 | 162 | @Override 163 | public TabView.TabTitle getTitle(int position) { 164 | 165 | return new TabView.TabTitle.Builder() 166 | .setContent(titles.get(position)) 167 | .setTextColor(Color.WHITE, 0xBBFFFFFF) 168 | .build(); 169 | } 170 | 171 | @Override 172 | public int getBackground(int position) { 173 | return 0; 174 | } 175 | 176 | @Override 177 | public boolean isViewFromObject(View view, Object object) { 178 | return view == object; 179 | } 180 | 181 | @Override 182 | public Object instantiateItem(ViewGroup container, int position) { 183 | TextView tv = new TextView(MainActivity.this); 184 | tv.setTextColor(Color.WHITE); 185 | tv.setGravity(Gravity.CENTER); 186 | tv.setText(titles.get(position)); 187 | tv.setTextSize(18); 188 | container.addView(tv); 189 | return tv; 190 | } 191 | 192 | @Override 193 | public void destroyItem(ViewGroup container, int position, Object object) { 194 | container.removeView((View) object); 195 | } 196 | } 197 | 198 | protected int dp2px(float dp) { 199 | final float scale = this.getResources().getDisplayMetrics().density; 200 | return (int) (dp * scale + 0.5f); 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/main/java/q/rorbin/verticaltablayoutdemo/MenuBean.java: -------------------------------------------------------------------------------- 1 | package q.rorbin.verticaltablayoutdemo; 2 | 3 | /** 4 | * Created by chqiu on 2016/8/3. 5 | */ 6 | public class MenuBean { 7 | public int mSelectIcon; 8 | public int mNormalIcon; 9 | public String mTitle; 10 | 11 | public MenuBean(int mSelectIcon, int mNormalIcon, String mTitle) { 12 | this.mSelectIcon = mSelectIcon; 13 | this.mNormalIcon = mNormalIcon; 14 | this.mTitle = mTitle; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/main/java/q/rorbin/verticaltablayoutdemo/TabFragment.java: -------------------------------------------------------------------------------- 1 | package q.rorbin.verticaltablayoutdemo; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.TextView; 11 | 12 | /** 13 | * Created by chqiu on 2017/1/16. 14 | */ 15 | 16 | public class TabFragment extends Fragment { 17 | @Nullable 18 | @Override 19 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 20 | TextView view = new TextView(inflater.getContext()); 21 | String text = getArguments().getString("index", "fragment"); 22 | view.setText(text); 23 | view.setTextSize(30); 24 | return view; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/main/java/q/rorbin/verticaltablayoutdemo/TabFragmentActivity.java: -------------------------------------------------------------------------------- 1 | package q.rorbin.verticaltablayoutdemo; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.Gravity; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | import q.rorbin.verticaltablayout.VerticalTabLayout; 12 | import q.rorbin.verticaltablayout.adapter.TabAdapter; 13 | import q.rorbin.verticaltablayout.widget.ITabView; 14 | import q.rorbin.verticaltablayout.widget.QTabView; 15 | import q.rorbin.verticaltablayout.widget.TabView; 16 | 17 | public class TabFragmentActivity extends AppCompatActivity { 18 | private VerticalTabLayout tabLayout; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_tab_fragment); 24 | tabLayout = (VerticalTabLayout) findViewById(R.id.tablayout); 25 | List fragments = getFragments(); 26 | tabLayout.setupWithFragment(getSupportFragmentManager(), R.id.fragment_container, fragments 27 | , new TabAdapter() { 28 | @Override 29 | public int getCount() { 30 | return 10; 31 | } 32 | 33 | @Override 34 | public QTabView.TabBadge getBadge(int position) { 35 | return null; 36 | } 37 | 38 | @Override 39 | public QTabView.TabIcon getIcon(int position) { 40 | return null; 41 | } 42 | 43 | @Override 44 | public QTabView.TabTitle getTitle(int position) { 45 | return new QTabView.TabTitle.Builder().setContent(String.valueOf(position)).build(); 46 | } 47 | 48 | @Override 49 | public int getBackground(int position) { 50 | return 0; 51 | } 52 | }); 53 | tabLayout.setTabSelected(6); 54 | } 55 | 56 | private List getFragments() { 57 | List fragments = new ArrayList<>(); 58 | for (int i = 0; i < 10; i++) { 59 | TabFragment fragment = new TabFragment(); 60 | Bundle bundle = new Bundle(); 61 | bundle.putString("index", String.valueOf(i)); 62 | fragment.setArguments(bundle); 63 | fragments.add(fragment); 64 | } 65 | return fragments; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 16 | 17 | 27 | 28 | 40 | 41 | 55 | 56 | 67 | 68 | 69 | 74 | 75 | -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/main/res/layout/activity_tab_fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 16 | 17 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 11 | 14 | 18 | -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qstumn/VerticalTabLayout/7588fc6766c097132aadcf37940aaea59e9f2e8e/verticaltablayoutdemo/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qstumn/VerticalTabLayout/7588fc6766c097132aadcf37940aaea59e9f2e8e/verticaltablayoutdemo/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qstumn/VerticalTabLayout/7588fc6766c097132aadcf37940aaea59e9f2e8e/verticaltablayoutdemo/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qstumn/VerticalTabLayout/7588fc6766c097132aadcf37940aaea59e9f2e8e/verticaltablayoutdemo/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qstumn/VerticalTabLayout/7588fc6766c097132aadcf37940aaea59e9f2e8e/verticaltablayoutdemo/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | VerticalTabLayoutDemo 3 | 4 | -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /verticaltablayoutdemo/src/test/java/q/rorbin/verticaltablayoutdemo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package q.rorbin.verticaltablayoutdemo; 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 | } --------------------------------------------------------------------------------