├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── hitomi │ │ └── thumbnailmenu │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── hitomi │ │ │ └── thumbnailmenu │ │ │ ├── Fragment1.java │ │ │ ├── Fragment2.java │ │ │ ├── Fragment3.java │ │ │ ├── Fragment4.java │ │ │ ├── Fragment5.java │ │ │ └── MainActivity.java │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── frament_1.xml │ │ ├── frament_2.xml │ │ ├── frament_3.xml │ │ ├── frament_4.xml │ │ └── frament_5.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ ├── ic_hamburg.png │ │ ├── ic_launcher.png │ │ └── profile_background.jpg │ │ ├── mipmap-xxhdpi │ │ ├── bg_fragment_1.jpeg │ │ ├── bg_fragment_2.jpeg │ │ ├── bg_fragment_3.jpeg │ │ ├── bg_fragment_4.jpeg │ │ ├── bg_fragment_5.jpg │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── hitomi │ └── thumbnailmenu │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── preview ├── menu_bottom.gif ├── menu_left.gif └── menu_right.gif ├── settings.gradle └── tmlibrary ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src └── main ├── AndroidManifest.xml ├── java └── com │ └── hitomi │ └── tmlibrary │ ├── ThumbnailAnimator.java │ ├── ThumbnailContainer.java │ ├── ThumbnailFactory.java │ ├── ThumbnailMenu.java │ └── TransitionLayout.java └── res └── values ├── attrs.xml └── strings.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ThumbnailMenu 2 | 3 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-ThumbnailMenu-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/4297) 4 | 5 | 这是一个简单而精致的 Fragment 菜单控件,它可以让你切换 Fragment 的时候不再单调、死板。 6 | 7 | # Preview 8 | 9 | 10 |
11 | 12 |
13 | 14 | 15 | # Usage 16 | 17 | 导入 tmlibrary module, 或者直接拷贝 com.hitomi.tmlibrary 包下所有 java 文件到您的项目中 18 | 19 | 布局文件中: 20 | 21 | 26 | 27 | 31 | 32 | 33 | 34 | 35 | 36 | RelativeLayout 可以让您编写自己的背景布局 37 | 38 | Activity 中: 39 | 40 | Fragment1 fragment1 = new Fragment1(); 41 | Fragment2 fragment2 = new Fragment2(); 42 | Fragment3 fragment3 = new Fragment3(); 43 | Fragment4 fragment4 = new Fragment4(); 44 | Fragment5 fragment5 = new Fragment5(); 45 | 46 | fragmentList.add(fragment5); 47 | fragmentList.add(fragment4); 48 | fragmentList.add(fragment3); 49 | fragmentList.add(fragment2); 50 | fragmentList.add(fragment1); 51 | 52 | FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) { 53 | @Override 54 | public Fragment getItem(int position) { 55 | return fragmentList.get(position); 56 | } 57 | 58 | @Override 59 | public int getCount() { 60 | return fragmentList.size(); 61 | } 62 | 63 | }; 64 | thumMenu.setAdapter(adapter); 65 | 66 | # Attributes 67 | 68 | 69 | 70 | 71 | 72 | 73 | 支持三种方向: 74 | left :缩略图置于屏幕左侧 75 | bottom : 缩略图置于屏幕底部 76 | right : 缩略图置于屏幕右侧 77 | 78 | 79 | 支持缩略图大小自定义 80 | scale_ratio :取值为 0.1f 到 1.0f 之间。 81 | 82 | 83 | #Licence 84 | 85 | MIT 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | applicationId "com.hitomi.thumbnailmenu" 9 | minSdkVersion 14 10 | targetSdkVersion 24 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 | compile 'com.android.support:appcompat-v7:24.1.1' 25 | compile project(':tmlibrary') 26 | } 27 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\androidstuido_sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/hitomi/thumbnailmenu/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.hitomi.thumbnailmenu; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/hitomi/thumbnailmenu/Fragment1.java: -------------------------------------------------------------------------------- 1 | package com.hitomi.thumbnailmenu; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | public class Fragment1 extends Fragment { 12 | @Override 13 | public void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | } 16 | 17 | @Nullable 18 | @Override 19 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 20 | return inflater.inflate(R.layout.frament_1, container, false); 21 | } 22 | 23 | @Override 24 | public void onActivityCreated(Bundle savedInstanceState) { 25 | super.onActivityCreated(savedInstanceState); 26 | } 27 | 28 | @Override 29 | public void onAttach(Context context) { 30 | super.onAttach(context); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/com/hitomi/thumbnailmenu/Fragment2.java: -------------------------------------------------------------------------------- 1 | package com.hitomi.thumbnailmenu; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | public class Fragment2 extends Fragment { 12 | @Override 13 | public void onActivityCreated(Bundle savedInstanceState) { 14 | super.onActivityCreated(savedInstanceState); 15 | } 16 | 17 | @Nullable 18 | @Override 19 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 20 | return inflater.inflate(R.layout.frament_2, container, false); 21 | } 22 | 23 | @Override 24 | public void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | } 27 | 28 | @Override 29 | public void onAttach(Context context) { 30 | super.onAttach(context); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/com/hitomi/thumbnailmenu/Fragment3.java: -------------------------------------------------------------------------------- 1 | package com.hitomi.thumbnailmenu; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | public class Fragment3 extends Fragment { 12 | @Override 13 | public void onAttach(Context context) { 14 | super.onAttach(context); 15 | } 16 | 17 | @Override 18 | public void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | } 21 | 22 | @Nullable 23 | @Override 24 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 25 | System.out.println("create"); 26 | return inflater.inflate(R.layout.frament_3, container, false); 27 | } 28 | 29 | @Override 30 | public void onActivityCreated(Bundle savedInstanceState) { 31 | super.onActivityCreated(savedInstanceState); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/hitomi/thumbnailmenu/Fragment4.java: -------------------------------------------------------------------------------- 1 | package com.hitomi.thumbnailmenu; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | /** 12 | * Created by peijiadi on 16/1/18. 13 | */ 14 | public class Fragment4 extends Fragment { 15 | @Override 16 | public void onAttach(Context context) { 17 | super.onAttach(context); 18 | } 19 | 20 | @Override 21 | public void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | } 24 | 25 | @Nullable 26 | @Override 27 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 28 | return inflater.inflate(R.layout.frament_4, container, false); 29 | } 30 | 31 | @Override 32 | public void onActivityCreated(Bundle savedInstanceState) { 33 | super.onActivityCreated(savedInstanceState); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/hitomi/thumbnailmenu/Fragment5.java: -------------------------------------------------------------------------------- 1 | package com.hitomi.thumbnailmenu; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | /** 12 | * Created by peijiadi on 16/1/18. 13 | */ 14 | public class Fragment5 extends Fragment { 15 | @Override 16 | public void onAttach(Context context) { 17 | super.onAttach(context); 18 | } 19 | 20 | @Override 21 | public void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | } 24 | 25 | @Nullable 26 | @Override 27 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 28 | return inflater.inflate(R.layout.frament_5, container, false); 29 | } 30 | 31 | @Override 32 | public void onActivityCreated(Bundle savedInstanceState) { 33 | super.onActivityCreated(savedInstanceState); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/hitomi/thumbnailmenu/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.hitomi.thumbnailmenu; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.support.v4.app.FragmentPagerAdapter; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.View; 8 | import android.widget.ImageView; 9 | 10 | import com.hitomi.tmlibrary.ThumbnailMenu; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | public class MainActivity extends AppCompatActivity { 16 | 17 | private List fragmentList = new ArrayList<>(); 18 | 19 | private ThumbnailMenu thumMenu; 20 | 21 | private ImageView ivMenu; 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_main); 27 | 28 | findViewById(); 29 | 30 | initFragment(); 31 | 32 | setViewListener(); 33 | } 34 | 35 | private void findViewById() { 36 | thumMenu = (ThumbnailMenu) findViewById(R.id.thumb); 37 | ivMenu = (ImageView) findViewById(R.id.iv_menu); 38 | } 39 | 40 | private void initFragment() { 41 | Fragment1 fragment1 = new Fragment1(); 42 | Fragment2 fragment2 = new Fragment2(); 43 | Fragment3 fragment3 = new Fragment3(); 44 | Fragment4 fragment4 = new Fragment4(); 45 | Fragment5 fragment5 = new Fragment5(); 46 | 47 | fragmentList.add(fragment5); 48 | fragmentList.add(fragment4); 49 | fragmentList.add(fragment3); 50 | fragmentList.add(fragment2); 51 | fragmentList.add(fragment1); 52 | 53 | FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) { 54 | @Override 55 | public Fragment getItem(int position) { 56 | return fragmentList.get(position); 57 | } 58 | 59 | @Override 60 | public int getCount() { 61 | return fragmentList.size(); 62 | } 63 | 64 | }; 65 | thumMenu.setAdapter(adapter); 66 | } 67 | 68 | private void setViewListener() { 69 | ivMenu.setOnClickListener(new View.OnClickListener() { 70 | @Override 71 | public void onClick(View view) { 72 | ivMenu.setVisibility(View.GONE); 73 | thumMenu.openMenu(); 74 | } 75 | }); 76 | 77 | thumMenu.setOnMenuCloseListener(new ThumbnailMenu.OnThumbnailMenuCloseListener() { 78 | @Override 79 | public void onMenuCloseListener() { 80 | ivMenu.setVisibility(View.VISIBLE); 81 | } 82 | }); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 20 | 21 | 22 | 23 | 24 | 25 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/res/layout/frament_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/frament_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/layout/frament_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/layout/frament_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/frament_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hitomis/ThumbnailMenu/89b4489e05c2d9023a896f03088a52ac2bb2ec62/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hitomis/ThumbnailMenu/89b4489e05c2d9023a896f03088a52ac2bb2ec62/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_hamburg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hitomis/ThumbnailMenu/89b4489e05c2d9023a896f03088a52ac2bb2ec62/app/src/main/res/mipmap-xhdpi/ic_hamburg.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hitomis/ThumbnailMenu/89b4489e05c2d9023a896f03088a52ac2bb2ec62/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/profile_background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hitomis/ThumbnailMenu/89b4489e05c2d9023a896f03088a52ac2bb2ec62/app/src/main/res/mipmap-xhdpi/profile_background.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/bg_fragment_1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hitomis/ThumbnailMenu/89b4489e05c2d9023a896f03088a52ac2bb2ec62/app/src/main/res/mipmap-xxhdpi/bg_fragment_1.jpeg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/bg_fragment_2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hitomis/ThumbnailMenu/89b4489e05c2d9023a896f03088a52ac2bb2ec62/app/src/main/res/mipmap-xxhdpi/bg_fragment_2.jpeg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/bg_fragment_3.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hitomis/ThumbnailMenu/89b4489e05c2d9023a896f03088a52ac2bb2ec62/app/src/main/res/mipmap-xxhdpi/bg_fragment_3.jpeg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/bg_fragment_4.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hitomis/ThumbnailMenu/89b4489e05c2d9023a896f03088a52ac2bb2ec62/app/src/main/res/mipmap-xxhdpi/bg_fragment_4.jpeg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/bg_fragment_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hitomis/ThumbnailMenu/89b4489e05c2d9023a896f03088a52ac2bb2ec62/app/src/main/res/mipmap-xxhdpi/bg_fragment_5.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hitomis/ThumbnailMenu/89b4489e05c2d9023a896f03088a52ac2bb2ec62/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hitomis/ThumbnailMenu/89b4489e05c2d9023a896f03088a52ac2bb2ec62/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | thumbnailmenu 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/hitomi/thumbnailmenu/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.hitomi.thumbnailmenu; 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 | } -------------------------------------------------------------------------------- /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.1.2' 9 | 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 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hitomis/ThumbnailMenu/89b4489e05c2d9023a896f03088a52ac2bb2ec62/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 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-2.10-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 | -------------------------------------------------------------------------------- /preview/menu_bottom.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hitomis/ThumbnailMenu/89b4489e05c2d9023a896f03088a52ac2bb2ec62/preview/menu_bottom.gif -------------------------------------------------------------------------------- /preview/menu_left.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hitomis/ThumbnailMenu/89b4489e05c2d9023a896f03088a52ac2bb2ec62/preview/menu_left.gif -------------------------------------------------------------------------------- /preview/menu_right.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hitomis/ThumbnailMenu/89b4489e05c2d9023a896f03088a52ac2bb2ec62/preview/menu_right.gif -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':tmlibrary' 2 | -------------------------------------------------------------------------------- /tmlibrary/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /tmlibrary/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | minSdkVersion 14 9 | targetSdkVersion 24 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(dir: 'libs', include: ['*.jar']) 23 | compile 'com.android.support:appcompat-v7:24.1.1' 24 | } 25 | -------------------------------------------------------------------------------- /tmlibrary/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:\androidstuido_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 | -------------------------------------------------------------------------------- /tmlibrary/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tmlibrary/src/main/java/com/hitomi/tmlibrary/ThumbnailAnimator.java: -------------------------------------------------------------------------------- 1 | package com.hitomi.tmlibrary; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorListenerAdapter; 5 | import android.animation.AnimatorSet; 6 | import android.animation.ObjectAnimator; 7 | import android.support.annotation.NonNull; 8 | import android.view.View; 9 | import android.view.animation.Interpolator; 10 | import android.view.animation.OvershootInterpolator; 11 | import android.widget.FrameLayout; 12 | import android.widget.HorizontalScrollView; 13 | import android.widget.ScrollView; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * 打开或关闭菜单动画实现类
19 | * Created by hitomi on 2016/8/26. 20 | * email : 196425254@qq.com 21 | */ 22 | public class ThumbnailAnimator { 23 | 24 | private final Interpolator interpolator = new OvershootInterpolator(); 25 | 26 | /** 27 | * 缩略图菜单 28 | */ 29 | private ThumbnailMenu thumbnailMenu; 30 | 31 | /** 32 | * 用于放置缩略图菜单的容器 ScrollView 33 | */ 34 | private final FrameLayout scrollLayout; 35 | 36 | /** 37 | * 用于放置缩略图菜单的容器 ViewGroup 38 | */ 39 | private ThumbnailContainer container; 40 | 41 | /** 42 | * Fragment 容器布局集合 43 | */ 44 | private List tranLayoutList; 45 | 46 | /** 47 | *菜单关闭时的监听器 48 | */ 49 | private ThumbnailMenu.OnThumbnailMenuCloseListener onMenuCloseListener; 50 | 51 | /** 52 | * 菜单方向 53 | */ 54 | private int direction; 55 | 56 | private boolean init = true; 57 | 58 | public ThumbnailAnimator(int direction, ThumbnailMenu thumbnailMenu, List tranLayoutList) { 59 | this.direction = direction; 60 | this.thumbnailMenu = thumbnailMenu; 61 | this.tranLayoutList = tranLayoutList; 62 | 63 | scrollLayout = (FrameLayout) thumbnailMenu.findViewWithTag(ThumbnailMenu.TAG_SCROLL_LAYOUT); 64 | container = (ThumbnailContainer) scrollLayout.getChildAt(0); 65 | } 66 | 67 | /** 68 | * 动画模式打开菜单 69 | */ 70 | public void openMenuAnimator() { 71 | scrollLayout.setVisibility(View.VISIBLE); 72 | switch (direction) { 73 | case ThumbnailFactory.MENU_DIRECTION_LEFT: 74 | case ThumbnailFactory.MENU_DIRECTION_RIGHT: 75 | horizontalOpenMenu(); 76 | break; 77 | 78 | case ThumbnailFactory.MENU_DIRECTION_BOTTOM: 79 | verticalOpenMun(); 80 | break; 81 | 82 | } 83 | } 84 | 85 | /** 86 | * 动画模式关闭菜单,并显示 transitionLayout 87 | * 88 | * @param transitionLayout 选中页面所在的 TransitionLayout 89 | * @param onMenuCloseListener 90 | */ 91 | public void closeMenuAnimator(TransitionLayout transitionLayout, 92 | ThumbnailMenu.OnThumbnailMenuCloseListener onMenuCloseListener) { 93 | this.onMenuCloseListener = onMenuCloseListener; 94 | switch (direction) { 95 | case ThumbnailFactory.MENU_DIRECTION_LEFT: 96 | case ThumbnailFactory.MENU_DIRECTION_RIGHT: 97 | horizontalCloseMenu(transitionLayout); 98 | break; 99 | 100 | case ThumbnailFactory.MENU_DIRECTION_BOTTOM: 101 | verticalCloseMenu(transitionLayout); 102 | break; 103 | } 104 | } 105 | 106 | /** 107 | * 纵向打开菜单 108 | */ 109 | private void verticalOpenMun() { 110 | float endTranX, endTranY; 111 | if (init) { 112 | for (int i = 0; i < tranLayoutList.size(); i++) { 113 | final TransitionLayout currTranLayout = tranLayoutList.get(i); 114 | final float tmpTranX = currTranLayout.getWidth() * (1.f - thumbnailMenu.getScaleRatio()) * .5f; 115 | 116 | endTranX = -tmpTranX + (i * (currTranLayout.getWidth() * thumbnailMenu.getScaleRatio() + ThumbnailMenu.THUM_MARGIN)); 117 | endTranY = currTranLayout.getHeight() * (1.f - thumbnailMenu.getScaleRatio()) * .5f; 118 | 119 | AnimatorSet animSet = makeOpenMenuAnimatorSet(endTranX, endTranY, currTranLayout); 120 | addOpenMenuAnimatorSetListener(animSet, currTranLayout, endTranY, i, tmpTranX); 121 | } 122 | init = false; 123 | } else { 124 | TransitionLayout showingTranLayout = (TransitionLayout) thumbnailMenu.getChildAt(thumbnailMenu.getChildCount() - 1); 125 | 126 | float singleThumMenuWidth = showingTranLayout.getWidth() * thumbnailMenu.getScaleRatio(); 127 | int menuIndex = tranLayoutList.indexOf(showingTranLayout); 128 | 129 | // 调整菜单滚动的位置 130 | int adjustScrollPosition = (int) (menuIndex * (singleThumMenuWidth + ThumbnailMenu.THUM_MARGIN)); 131 | HorizontalScrollView scrollView = (HorizontalScrollView) scrollLayout; 132 | scrollView.scrollTo(adjustScrollPosition, 0); 133 | 134 | // 当前 ScrollView 滚动的距离 135 | int scrollDistance = scrollView.getScrollX(); 136 | float tmpTranX = showingTranLayout.getWidth() * (1.f - thumbnailMenu.getScaleRatio()) * .5f; 137 | 138 | endTranX = -tmpTranX + (menuIndex * (singleThumMenuWidth + ThumbnailMenu.THUM_MARGIN)) - scrollDistance; 139 | endTranY = showingTranLayout.getHeight() * (1.f - thumbnailMenu.getScaleRatio()) * .5f; 140 | 141 | AnimatorSet animSet = makeOpenMenuAnimatorSet(endTranX, endTranY, showingTranLayout); 142 | addOpenMenuAnimatorSetListener(animSet, showingTranLayout, endTranY, menuIndex, tmpTranX); 143 | } 144 | } 145 | 146 | /** 147 | * 纵向(左侧或者右侧)关闭菜单,并显示选中的 TransitionLayout 148 | * 149 | * @param transitionLayout 选中页面所在的 TransitionLayout 150 | */ 151 | private void verticalCloseMenu(final TransitionLayout transitionLayout) { 152 | HorizontalScrollView scrollView = (HorizontalScrollView) scrollLayout; 153 | // 当前 ScrollView 滚动的距离 154 | final int scrollDistance = scrollView.getScrollX(); 155 | // 当前选中的 TransitionLayout 所在模型的 Left 156 | final int currTranLeft = ((FrameLayout) transitionLayout.getParent()).getLeft(); 157 | 158 | int tranTop = ((FrameLayout) transitionLayout.getParent()).getTop(); 159 | // 将选中 TransitionLayout 从其所在模型中移除并放置在 ThumbnailMenu 相对模型所在同一个位置上 160 | final int choosenMenuIndex = tranLayoutList.indexOf(transitionLayout); 161 | FrameLayout frameLayout = (FrameLayout) container.getChildAt(choosenMenuIndex); 162 | frameLayout.removeView(transitionLayout); 163 | 164 | final FrameLayout.LayoutParams frameParams = new FrameLayout.LayoutParams( 165 | transitionLayout.getWidth(), 166 | transitionLayout.getHeight()); 167 | frameParams.leftMargin = currTranLeft - scrollDistance; 168 | frameParams.topMargin = tranTop; 169 | transitionLayout.setLayoutParams(frameParams); 170 | 171 | thumbnailMenu.addView(transitionLayout); 172 | 173 | float endTranX = (thumbnailMenu.getWidth() - transitionLayout.getWidth()) * .5f - currTranLeft + scrollDistance; 174 | float endTranY = -frameParams.topMargin; 175 | 176 | AnimatorSet animSet = makeCloseMenuAnimatorSet(transitionLayout, endTranX, endTranY); 177 | addCloseMenuAnimatorSetListener(transitionLayout, frameParams, animSet); 178 | } 179 | 180 | /** 181 | * 横向(左侧或者右侧)打开菜单 182 | */ 183 | private void horizontalOpenMenu() { 184 | float endTranX, endTranY; 185 | if (init) { 186 | for (int i = 0; i < tranLayoutList.size(); i++) { 187 | TransitionLayout currTranLayout = tranLayoutList.get(i); 188 | float tmpTranY = currTranLayout.getHeight() * (1.f - thumbnailMenu.getScaleRatio()) * .5f; 189 | 190 | endTranX = currTranLayout.getWidth() * (1.f - thumbnailMenu.getScaleRatio()) * .5f; 191 | endTranY = -tmpTranY + (i * (currTranLayout.getHeight() * thumbnailMenu.getScaleRatio() + ThumbnailMenu.THUM_MARGIN)); 192 | 193 | AnimatorSet animSet = makeOpenMenuAnimatorSet(endTranX, endTranY, currTranLayout); 194 | addOpenMenuAnimatorSetListener(animSet, currTranLayout, tmpTranY, i, endTranX); 195 | } 196 | init = false; 197 | } else { 198 | TransitionLayout showingTranLayout = (TransitionLayout) thumbnailMenu.getChildAt(thumbnailMenu.getChildCount() - 1); 199 | 200 | float singleThumMenuHeight = showingTranLayout.getHeight() * thumbnailMenu.getScaleRatio(); 201 | int menuIndex = tranLayoutList.indexOf(showingTranLayout); 202 | 203 | // 调整菜单滚动的位置 204 | int adjustScrollPosition = (int) (menuIndex * (singleThumMenuHeight + ThumbnailMenu.THUM_MARGIN)); 205 | ScrollView scrollView = (ScrollView) scrollLayout; 206 | scrollView.scrollTo(0, adjustScrollPosition); 207 | 208 | // 当前 ScrollView 滚动的距离 209 | int scrollDistance = scrollView.getScrollY(); 210 | float tmpTranY = showingTranLayout.getHeight() * (1.f - thumbnailMenu.getScaleRatio()) * .5f; 211 | 212 | endTranX = showingTranLayout.getWidth() * (1.f - thumbnailMenu.getScaleRatio()) * .5f; 213 | endTranY = -tmpTranY + (menuIndex * (singleThumMenuHeight + ThumbnailMenu.THUM_MARGIN)) - scrollDistance; 214 | 215 | AnimatorSet animSet = makeOpenMenuAnimatorSet(endTranX, endTranY, showingTranLayout); 216 | addOpenMenuAnimatorSetListener(animSet, showingTranLayout, tmpTranY, menuIndex, endTranX); 217 | } 218 | 219 | } 220 | 221 | /** 222 | * 横向(左侧或者右侧)关闭菜单,并显示选中的 TransitionLayout 223 | * 224 | * @param transitionLayout 选中页面所在的TransitionLayout 225 | */ 226 | private void horizontalCloseMenu(final TransitionLayout transitionLayout) { 227 | // 当前 ScrollView 滚动的距离 228 | final int scrollDistance = scrollLayout.getScrollY(); 229 | // 当前选中的 TransitionLayout 所在模型的 Top 230 | final int currTranTop = ((FrameLayout) transitionLayout.getParent()).getTop(); 231 | 232 | // 将选中 TransitionLayout 从其所在模型中移除并放置在 ThumbnailMenu 相对模型所在同一个位置上 233 | final int choosenMenuIndex = tranLayoutList.indexOf(transitionLayout); 234 | FrameLayout frameLayout = (FrameLayout) container.getChildAt(choosenMenuIndex); 235 | frameLayout.removeView(transitionLayout); 236 | 237 | final FrameLayout.LayoutParams frameParams = new FrameLayout.LayoutParams( 238 | transitionLayout.getWidth(), 239 | transitionLayout.getHeight()); 240 | frameParams.topMargin = currTranTop - scrollDistance; 241 | transitionLayout.setLayoutParams(frameParams); 242 | 243 | thumbnailMenu.addView(transitionLayout); 244 | 245 | float endTranX = (thumbnailMenu.getWidth() - transitionLayout.getWidth()) * .5f; 246 | float endTranY = (thumbnailMenu.getHeight() - transitionLayout.getHeight()) * .5f - currTranTop + scrollDistance; 247 | 248 | AnimatorSet animSet = makeCloseMenuAnimatorSet(transitionLayout, endTranX, endTranY); 249 | addCloseMenuAnimatorSetListener(transitionLayout, frameParams, animSet); 250 | 251 | } 252 | 253 | private void addCloseMenuAnimatorSetListener(final TransitionLayout transitionLayout, 254 | final FrameLayout.LayoutParams frameParams, 255 | AnimatorSet animSet) { 256 | 257 | animSet.addListener(new AnimatorListenerAdapter() { 258 | @Override 259 | public void onAnimationEnd(Animator animation) { 260 | frameParams.leftMargin = 0; 261 | frameParams.topMargin = 0; 262 | // 还原选中的 TransitionLayout 263 | transitionLayout.setTranslationX(0); 264 | transitionLayout.setTranslationY(0); 265 | transitionLayout.setLayoutParams(frameParams); 266 | 267 | if (onMenuCloseListener != null) { 268 | onMenuCloseListener.onMenuCloseListener(); 269 | } 270 | scrollLayout.setVisibility(View.GONE); 271 | } 272 | }); 273 | } 274 | 275 | /** 276 | * 创建打开菜单的动画集 277 | * 278 | * @param endTranX 279 | * @param endTranY 280 | * @param transitionLayout 281 | * @return 282 | */ 283 | @NonNull 284 | private AnimatorSet makeOpenMenuAnimatorSet(float endTranX, float endTranY, TransitionLayout transitionLayout) { 285 | endTranX = direction == ThumbnailFactory.MENU_DIRECTION_LEFT ? -endTranX : endTranX; 286 | 287 | ObjectAnimator scaleXAnima = ObjectAnimator.ofFloat( 288 | transitionLayout, "scaleX", transitionLayout.getScaleX(), thumbnailMenu.getScaleRatio()); 289 | ObjectAnimator scaleYAnima = ObjectAnimator.ofFloat( 290 | transitionLayout, "scaleY", transitionLayout.getScaleY(), thumbnailMenu.getScaleRatio()); 291 | 292 | ObjectAnimator tranXAnima = ObjectAnimator.ofFloat( 293 | transitionLayout, "translationX", transitionLayout.getTranslationX(), endTranX); 294 | ObjectAnimator tranYAnima = ObjectAnimator.ofFloat( 295 | transitionLayout, "translationY", transitionLayout.getTranslationY(), endTranY); 296 | 297 | AnimatorSet animSet = new AnimatorSet(); 298 | animSet.setDuration(300); 299 | animSet.setInterpolator(interpolator); 300 | animSet.play(scaleXAnima).with(scaleYAnima).before(tranXAnima).before(tranYAnima); 301 | animSet.start(); 302 | return animSet; 303 | } 304 | 305 | /** 306 | * 创建关闭菜单的动画集 307 | * 308 | * @param transitionLayout 309 | * @param endTranX 310 | * @param endTranY 311 | * @return 312 | */ 313 | @NonNull 314 | private AnimatorSet makeCloseMenuAnimatorSet(TransitionLayout transitionLayout, float endTranX, float endTranY) { 315 | ObjectAnimator scaleXAnima = ObjectAnimator.ofFloat( 316 | transitionLayout, "scaleX", transitionLayout.getScaleX(), transitionLayout.getScaleX() / thumbnailMenu.getScaleRatio()); 317 | ObjectAnimator scaleYAnima = ObjectAnimator.ofFloat( 318 | transitionLayout, "scaleY", transitionLayout.getScaleX(), transitionLayout.getScaleY() / thumbnailMenu.getScaleRatio()); 319 | 320 | float currTranX = direction == ThumbnailFactory.MENU_DIRECTION_RIGHT ? 321 | -transitionLayout.getTranslationX() : 322 | transitionLayout.getTranslationX(); 323 | 324 | ObjectAnimator tranXAnima = ObjectAnimator.ofFloat( 325 | transitionLayout, "translationX", currTranX, endTranX); 326 | ObjectAnimator tranYAnima = ObjectAnimator.ofFloat( 327 | transitionLayout, "translationY", transitionLayout.getTranslationY(), endTranY); 328 | 329 | AnimatorSet animSet = new AnimatorSet(); 330 | animSet.setDuration(300); 331 | animSet.play(tranXAnima).with(tranYAnima).before(scaleXAnima).before(scaleYAnima); 332 | animSet.setInterpolator(interpolator); 333 | animSet.start(); 334 | return animSet; 335 | } 336 | 337 | /** 338 | * 为菜单打开动画集添加一个监听器 339 | * 340 | * @param animSet 341 | * @param transitionLayout 342 | * @param tmpTranY 343 | * @param index 344 | * @param finalEndTranX 345 | */ 346 | private void addOpenMenuAnimatorSetListener(AnimatorSet animSet, final TransitionLayout transitionLayout, 347 | final float tmpTranY, final int index, final float finalEndTranX) { 348 | animSet.addListener(new AnimatorListenerAdapter() { 349 | @Override 350 | public void onAnimationEnd(Animator animation) { 351 | // 1. 将 transitionLayout 从 menu 容器中移除 352 | thumbnailMenu.removeViewAt(thumbnailMenu.indexOfChild(transitionLayout)); 353 | 354 | // 2. 将 transitionLayout 放入菜单容器中 355 | // 设置为原来的宽高大小,是因为之前缩小过 356 | FrameLayout.LayoutParams frameParams = new FrameLayout.LayoutParams( 357 | transitionLayout.getWidth(), 358 | transitionLayout.getHeight() 359 | ); 360 | FrameLayout frameLayout = (FrameLayout) container.getChildAt(index); 361 | // 调整位置 362 | transitionLayout.setTranslationX(-finalEndTranX); 363 | transitionLayout.setTranslationY(-tmpTranY); 364 | // 将缩小后的 transitionLayout 放入模型中 365 | frameLayout.addView(transitionLayout, frameParams); 366 | } 367 | }); 368 | } 369 | } 370 | -------------------------------------------------------------------------------- /tmlibrary/src/main/java/com/hitomi/tmlibrary/ThumbnailContainer.java: -------------------------------------------------------------------------------- 1 | package com.hitomi.tmlibrary; 2 | 3 | import android.content.Context; 4 | import android.widget.LinearLayout; 5 | 6 | /** 7 | * ScrollView/HorizontalScrollView 中的 唯一子 ViewGroup
8 | * 用于放置缩略图模型 9 | * Created by hitomi on 2016/8/29. 10 | */ 11 | public class ThumbnailContainer extends LinearLayout { 12 | 13 | private int direction; 14 | 15 | public ThumbnailContainer(Context context, int direction) { 16 | super(context); 17 | 18 | this.direction = direction; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /tmlibrary/src/main/java/com/hitomi/tmlibrary/ThumbnailFactory.java: -------------------------------------------------------------------------------- 1 | package com.hitomi.tmlibrary; 2 | 3 | import android.content.Context; 4 | import android.widget.FrameLayout; 5 | import android.widget.HorizontalScrollView; 6 | import android.widget.LinearLayout; 7 | import android.widget.ScrollView; 8 | 9 | /** 10 | * 依据方向创建不同位置的菜单容器 ScrollView / HorizontalScrollView
11 | * 左侧和右侧为 ScrollView, 底部为 HorizontalScrollView
12 | * 13 | * Created by hitomi on 2016/8/19. 14 | * email : 196425254@qq.com 15 | */ 16 | class ThumbnailFactory { 17 | 18 | static final int MENU_DIRECTION_LEFT = 1000; 19 | 20 | static final int MENU_DIRECTION_BOTTOM = 1001; 21 | 22 | static final int MENU_DIRECTION_RIGHT = 1002; 23 | 24 | FrameLayout createMenuContainer(Context context, int direction) { 25 | FrameLayout scrollLayout; 26 | 27 | LinearLayout containerLayout = new ThumbnailContainer(context, direction); 28 | ScrollView.LayoutParams scrollParams = new ScrollView.LayoutParams( 29 | ScrollView.LayoutParams.MATCH_PARENT, ScrollView.LayoutParams.MATCH_PARENT); 30 | containerLayout.setLayoutParams(scrollParams); 31 | 32 | switch (direction) { 33 | case MENU_DIRECTION_LEFT: 34 | scrollLayout = new ScrollView(context); 35 | scrollLayout.setVerticalScrollBarEnabled(false); 36 | containerLayout.setOrientation(LinearLayout.VERTICAL); 37 | break; 38 | case MENU_DIRECTION_RIGHT: 39 | scrollLayout = new ScrollView(context); 40 | scrollLayout.setVerticalScrollBarEnabled(false); 41 | containerLayout.setOrientation(LinearLayout.VERTICAL); 42 | break; 43 | case MENU_DIRECTION_BOTTOM: 44 | scrollLayout = new HorizontalScrollView(context); 45 | scrollLayout.setHorizontalScrollBarEnabled(false); 46 | containerLayout.setOrientation(LinearLayout.HORIZONTAL); 47 | break; 48 | default: 49 | scrollLayout = new ScrollView(context); 50 | scrollLayout.setVerticalScrollBarEnabled(false); 51 | containerLayout.setOrientation(LinearLayout.VERTICAL); 52 | } 53 | scrollLayout.addView(containerLayout); 54 | return scrollLayout; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /tmlibrary/src/main/java/com/hitomi/tmlibrary/ThumbnailMenu.java: -------------------------------------------------------------------------------- 1 | package com.hitomi.tmlibrary; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.support.v4.view.PagerAdapter; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.FrameLayout; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; 15 | 16 | /** 17 | * 缩略图菜单 18 | * Created by hitomi on 2016/8/19. 19 | * email : 196425254@qq.com 20 | */ 21 | public class ThumbnailMenu extends FrameLayout { 22 | 23 | static final float SCALE_RATIO = .45f; 24 | 25 | static final int THUM_MARGIN = 2; 26 | 27 | static final String TAG_SCROLL_LAYOUT = "tag_scroll_layout"; 28 | 29 | private ThumbnailFactory factory; 30 | 31 | private ThumbnailAnimator thumbnailAnimator; 32 | 33 | private ThumbnailMenuChooser thumbnailMenuChooser; 34 | 35 | private FrameLayout thumScrollLayout; 36 | 37 | private PagerAdapter pageAdapter; 38 | 39 | private OnThumbnailMenuCloseListener menuCloseListener; 40 | 41 | private List objects; 42 | 43 | private List tranLayoutList; 44 | 45 | /** 46 | * 缩略图菜单位置方向 47 | */ 48 | private int direction = ThumbnailFactory.MENU_DIRECTION_BOTTOM; 49 | 50 | /** 51 | * 缩略图当前缩放比率 52 | */ 53 | private float scaleRation = SCALE_RATIO; 54 | 55 | /** 56 | * 第一次初始化标记 57 | */ 58 | private boolean init = true; 59 | 60 | /** 61 | * 菜单是否打开 62 | */ 63 | private boolean isOpen; 64 | 65 | /** 66 | * 页面数量 67 | */ 68 | private int pageCount; 69 | 70 | public ThumbnailMenu(Context context) { 71 | this(context, null); 72 | } 73 | 74 | public ThumbnailMenu(Context context, AttributeSet attrs) { 75 | this(context, attrs, 0); 76 | } 77 | 78 | public ThumbnailMenu(Context context, AttributeSet attrs, int defStyleAttr) { 79 | super(context, attrs, defStyleAttr); 80 | 81 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ThumbnailMenu); 82 | direction = typedArray.getInt(R.styleable.ThumbnailMenu_menu_direction, direction); 83 | scaleRation = typedArray.getFloat(R.styleable.ThumbnailMenu_scale_ratio, scaleRation); 84 | scaleRation = scaleRation >= 1.f ? 1.f : scaleRation; 85 | scaleRation = scaleRation <= .1f ? .1f : scaleRation; 86 | typedArray.recycle(); 87 | 88 | init(); 89 | } 90 | 91 | private void init() { 92 | isOpen = false; 93 | objects = new ArrayList(); 94 | tranLayoutList = new ArrayList<>(); 95 | 96 | thumbnailMenuChooser = new ThumbnailMenuChooser(); 97 | factory = new ThumbnailFactory(); 98 | } 99 | 100 | @Override 101 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 102 | super.onLayout(changed, left, top, right, bottom); 103 | if (init) { 104 | thumScrollLayout = factory.createMenuContainer(getContext(), direction); 105 | thumScrollLayout.setTag(TAG_SCROLL_LAYOUT); 106 | thumScrollLayout.setVisibility(View.GONE); 107 | addView(thumScrollLayout); 108 | 109 | thumbnailAnimator = new ThumbnailAnimator(direction, this, tranLayoutList); 110 | buildingModels(); 111 | 112 | init = false; 113 | } 114 | } 115 | 116 | /** 117 | * 绑定页面适配器 118 | * 119 | * @param adapter 120 | */ 121 | public void setAdapter(PagerAdapter adapter) { 122 | if (pageAdapter != null) { 123 | pageAdapter.startUpdate(this); 124 | for (int i = 0; i < adapter.getCount(); i++) { 125 | pageAdapter.destroyItem((ViewGroup) getChildAt(i + 1), i, objects.get(i)); 126 | } 127 | pageAdapter.finishUpdate(this); 128 | } 129 | 130 | pageAdapter = adapter; 131 | pageCount = pageAdapter.getCount(); 132 | 133 | LayoutParams layoutParams = new LayoutParams(MATCH_PARENT, MATCH_PARENT); 134 | for (int i = 0; i < pageCount; i++) { 135 | TransitionLayout frameLayout = new TransitionLayout(getContext()); 136 | frameLayout.setId(i + 1);// id 不能为0 137 | frameLayout.setLayoutParams(layoutParams); 138 | frameLayout.setOnClickListener(thumbnailMenuChooser); 139 | addView(frameLayout); 140 | tranLayoutList.add(0, frameLayout); // 倒序添加 141 | } 142 | 143 | for (int i = 0; i < pageCount; i++) { 144 | Object object = pageAdapter.instantiateItem((ViewGroup) getChildAt(i + 1), i); 145 | objects.add(object); 146 | } 147 | pageAdapter.finishUpdate(this); 148 | } 149 | 150 | /** 151 | * 获取缩略图菜单容器中的 ScrollView 中唯一 ViewGroup [这里是LinearLayout] 152 | * 153 | * @return 154 | */ 155 | public ThumbnailContainer getThumContainner() { 156 | return (ThumbnailContainer) thumScrollLayout.getChildAt(0); 157 | } 158 | 159 | /** 160 | * 创建 modelCount 数量的缩略图模型添加到缩略图菜单容器中 161 | */ 162 | private void buildingModels() { 163 | final ThumbnailContainer containerLayout = getThumContainner(); 164 | containerLayout.removeAllViews(); 165 | 166 | for (int i = 0; i < pageCount; i++) { 167 | ThumbnailContainer.LayoutParams containerLayoutParams = new ThumbnailContainer.LayoutParams( 168 | (int) (getWidth() * scaleRation), (int) (getHeight() * scaleRation)); 169 | if (i != 0) { 170 | if (direction == ThumbnailFactory.MENU_DIRECTION_BOTTOM) { 171 | containerLayoutParams.leftMargin = THUM_MARGIN; 172 | } else { 173 | containerLayoutParams.topMargin = THUM_MARGIN; 174 | } 175 | } 176 | 177 | if (direction == ThumbnailFactory.MENU_DIRECTION_BOTTOM) { 178 | containerLayoutParams.topMargin = getHeight() - containerLayoutParams.height; 179 | } 180 | if (direction == ThumbnailFactory.MENU_DIRECTION_RIGHT) { 181 | containerLayoutParams.leftMargin = getWidth() - containerLayoutParams.width; 182 | } 183 | 184 | FrameLayout modelLayout = new FrameLayout(getContext()); 185 | modelLayout.setTag(i); 186 | containerLayout.addView(modelLayout, containerLayoutParams); 187 | } 188 | } 189 | 190 | /** 191 | * 打开菜单 192 | */ 193 | public void openMenu() { 194 | if (!isOpen) { 195 | isOpen = true; 196 | thumbnailAnimator.openMenuAnimator(); 197 | } 198 | } 199 | 200 | /** 201 | * 关闭菜单 202 | * 203 | * @param transitionLayout 204 | */ 205 | private void closeMenu(TransitionLayout transitionLayout) { 206 | if (isOpen) { 207 | isOpen = false; 208 | thumbnailAnimator.closeMenuAnimator(transitionLayout, menuCloseListener); 209 | } 210 | } 211 | 212 | /** 213 | * 菜单是否打开 214 | * 215 | * @return 216 | */ 217 | public boolean isOpen() { 218 | return isOpen; 219 | } 220 | 221 | /** 222 | * 返回缩略图缩放的比率 223 | * 224 | * @return 225 | */ 226 | public float getScaleRatio() { 227 | return scaleRation; 228 | } 229 | 230 | public void setOnMenuCloseListener(OnThumbnailMenuCloseListener menuCloseListener) { 231 | this.menuCloseListener = menuCloseListener; 232 | } 233 | 234 | public interface OnThumbnailMenuCloseListener { 235 | void onMenuCloseListener(); 236 | } 237 | 238 | private class ThumbnailMenuChooser implements OnClickListener { 239 | 240 | @Override 241 | public void onClick(View view) { 242 | if (isOpen && view instanceof TransitionLayout) { 243 | TransitionLayout choosenLayout = (TransitionLayout) view; 244 | closeMenu(choosenLayout); 245 | } 246 | } 247 | } 248 | } 249 | -------------------------------------------------------------------------------- /tmlibrary/src/main/java/com/hitomi/tmlibrary/TransitionLayout.java: -------------------------------------------------------------------------------- 1 | package com.hitomi.tmlibrary; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.View; 6 | import android.widget.FrameLayout; 7 | 8 | /** 9 | * Fragment 实例化的时候需要的容器 10 | * Created by hitomi on 2016/8/22. 11 | */ 12 | public class TransitionLayout extends FrameLayout { 13 | 14 | private final View view; 15 | 16 | public TransitionLayout(Context context) { 17 | this(context, null); 18 | } 19 | 20 | public TransitionLayout(Context context, AttributeSet attrs) { 21 | this(context, attrs, 0); 22 | } 23 | 24 | public TransitionLayout(Context context, AttributeSet attrs, int defStyleAttr) { 25 | super(context, attrs, defStyleAttr); 26 | 27 | view = getChildAt(0); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /tmlibrary/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /tmlibrary/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | TMLibrary 3 | 4 | --------------------------------------------------------------------------------