├── .gitignore ├── README.md ├── art └── 01.gif ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── licrafter │ │ └── exp │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── licrafter │ │ │ └── exp │ │ │ ├── ExpandableHeader.java │ │ │ └── ExpandableLayout.java │ └── res │ │ └── values │ │ ├── attr.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── licrafter │ └── exp │ └── ExampleUnitTest.java ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── licrafter │ │ └── sample │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── licrafter │ │ │ └── sample │ │ │ ├── MainActivity.java │ │ │ ├── repo │ │ │ ├── ImageModel.java │ │ │ └── Repo.java │ │ │ └── utils │ │ │ └── Utils.java │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── fragment_pager.xml │ │ ├── include_toolbar.xml │ │ ├── item_sample.xml │ │ ├── layout_banner_image.xml │ │ ├── layout_toolar_1.xml │ │ └── layout_toolbar_2.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_action_back.png │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── licrafter │ └── sample │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | .idea/ 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ExpandableLayout 2 | Android仿`小红书`笔记详情页的滑动可伸缩的布局,具有滑动临界值,自动滑动,内容部分和Header的滑动视差等效果.[视频效果演示](http://7vzpfd.com1.z0.glb.clouddn.com/shamuNBD90Zlijx02052017201440.mp4) 3 | 4 | ![](http://7vzpfd.com1.z0.glb.clouddn.com/01.gif) 5 | -------------------------------------------------------------------------------- /art/01.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shellljx/ExpandableLayout/65724dd4a587b499f236deae9cd3651e5f6413e1/art/01.gif -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.3' 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 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shellljx/ExpandableLayout/65724dd4a587b499f236deae9cd3651e5f6413e1/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.14.1-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 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | 7 | defaultConfig { 8 | minSdkVersion 14 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | } 23 | 24 | dependencies { 25 | compile fileTree(dir: 'libs', include: ['*.jar']) 26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 27 | exclude group: 'com.android.support', module: 'support-annotations' 28 | }) 29 | compile 'com.android.support:design:25.1.0' 30 | compile 'com.android.support:appcompat-v7:25.1.0' 31 | testCompile 'junit:junit:4.12' 32 | } 33 | -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk-macosx/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /library/src/androidTest/java/com/licrafter/exp/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.licrafter.exp; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.licrafter.exp.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /library/src/main/java/com/licrafter/exp/ExpandableHeader.java: -------------------------------------------------------------------------------- 1 | package com.licrafter.exp; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.MotionEvent; 6 | import android.widget.FrameLayout; 7 | 8 | /** 9 | * author: shell 10 | * date 2017/1/11 下午9:50 11 | **/ 12 | public class ExpandableHeader extends FrameLayout { 13 | 14 | private HeaderCollapseListener mListener; 15 | private float mLastedY; 16 | private float mLastX; 17 | private int mThreshold; 18 | private boolean mScrolling; 19 | 20 | 21 | public ExpandableHeader(Context context) { 22 | this(context, null); 23 | } 24 | 25 | public ExpandableHeader(Context context, AttributeSet attrs) { 26 | this(context, attrs, 0); 27 | } 28 | 29 | public ExpandableHeader(Context context, AttributeSet attrs, int defStyleAttr) { 30 | super(context, attrs, defStyleAttr); 31 | } 32 | 33 | @Override 34 | public boolean dispatchTouchEvent(MotionEvent ev) { 35 | switch (ev.getActionMasked()) { 36 | case MotionEvent.ACTION_CANCEL: 37 | case MotionEvent.ACTION_UP: 38 | mScrolling = false; 39 | } 40 | return super.dispatchTouchEvent(ev); 41 | } 42 | 43 | @Override 44 | public boolean onInterceptTouchEvent(MotionEvent ev) { 45 | float y = ev.getRawY(); 46 | float x = ev.getRawX(); 47 | switch (ev.getActionMasked()) { 48 | case MotionEvent.ACTION_DOWN: 49 | mLastedY = y; 50 | mLastX = x; 51 | break; 52 | case MotionEvent.ACTION_MOVE: 53 | float dy = mLastedY - y; 54 | float dx = mLastX - x; 55 | if (Math.abs(dy) > Math.abs(dx)) { 56 | mLastedY = y; 57 | mScrolling = false; 58 | return true; 59 | } else { 60 | mScrolling = true; 61 | } 62 | break; 63 | } 64 | return super.onInterceptTouchEvent(ev); 65 | } 66 | 67 | @Override 68 | public boolean onTouchEvent(MotionEvent event) { 69 | float y = event.getRawY(); 70 | switch (event.getActionMasked()) { 71 | case MotionEvent.ACTION_DOWN: 72 | mLastedY = y; 73 | return true; 74 | case MotionEvent.ACTION_MOVE: 75 | float dy = mLastedY - y; 76 | if (Math.abs(dy) > mThreshold && dy > 0 && mListener != null) { 77 | mListener.onHeaderCollapse(); 78 | } 79 | return true; 80 | } 81 | return super.onTouchEvent(event); 82 | } 83 | 84 | public void setThreshold(int threshold) { 85 | mThreshold = threshold; 86 | } 87 | 88 | public void setTopMargin(int topMargin) { 89 | getMarginLayoutParams().topMargin = topMargin; 90 | requestLayout(); 91 | } 92 | 93 | public void setHeight(int height) { 94 | getMarginLayoutParams().topMargin = 0; 95 | getMarginLayoutParams().height = height; 96 | requestLayout(); 97 | if (mListener != null) { 98 | mListener.onHeaderHeightChange(height); 99 | } 100 | } 101 | 102 | public MarginLayoutParams getMarginLayoutParams() { 103 | return (MarginLayoutParams) getLayoutParams(); 104 | } 105 | 106 | public boolean isScrolling() { 107 | return mScrolling; 108 | } 109 | 110 | 111 | public void setCollapseListener(HeaderCollapseListener listener) { 112 | mListener = listener; 113 | } 114 | 115 | public interface HeaderCollapseListener { 116 | void onHeaderCollapse(); 117 | 118 | void onHeaderHeightChange(int height); 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /library/src/main/java/com/licrafter/exp/ExpandableLayout.java: -------------------------------------------------------------------------------- 1 | package com.licrafter.exp; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ObjectAnimator; 5 | import android.content.Context; 6 | import android.support.v4.widget.NestedScrollView; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.util.AttributeSet; 10 | import android.view.MotionEvent; 11 | import android.view.View; 12 | import android.view.ViewConfiguration; 13 | import android.view.animation.AccelerateDecelerateInterpolator; 14 | import android.webkit.WebView; 15 | import android.widget.AdapterView; 16 | import android.widget.FrameLayout; 17 | import android.widget.ScrollView; 18 | 19 | /** 20 | * author: shell 21 | * date 2017/1/11 下午9:49 22 | **/ 23 | public class ExpandableLayout extends FrameLayout implements ExpandableHeader.HeaderCollapseListener { 24 | 25 | private static final float DEFAULT_FACTOR = 0.5f; 26 | 27 | private ExpandableHeader mHeader; 28 | private OnLayoutScrollListener mListener; 29 | 30 | private int mTouchSlop; 31 | private int mMinMargin; 32 | private int mMaxMargin; 33 | private int mThreshold; 34 | private float mFactor; 35 | private float mLastedY; 36 | private boolean mDraging; 37 | private boolean mCollapsed;//完全遮盖住header为坍塌状态 38 | private boolean mSticky; 39 | private Animator mAnimator; 40 | private int start; 41 | private int end; 42 | 43 | public ExpandableLayout(Context context) { 44 | this(context, null); 45 | } 46 | 47 | public ExpandableLayout(Context context, AttributeSet attrs) { 48 | this(context, attrs, 0); 49 | } 50 | 51 | public ExpandableLayout(Context context, AttributeSet attrs, int defStyleAttr) { 52 | super(context, attrs, defStyleAttr); 53 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); 54 | mFactor = DEFAULT_FACTOR; 55 | } 56 | 57 | @Override 58 | protected void onFinishInflate() { 59 | super.onFinishInflate(); 60 | if (getChildCount() > 1) { 61 | throw new IllegalStateException("ExpandableLayout can host only one direct child"); 62 | } 63 | } 64 | 65 | @Override 66 | public boolean onInterceptTouchEvent(MotionEvent ev) { 67 | float y = ev.getRawY(); 68 | switch (ev.getActionMasked()) { 69 | case MotionEvent.ACTION_DOWN: 70 | mLastedY = y; 71 | break; 72 | case MotionEvent.ACTION_MOVE: 73 | float dy = mLastedY - y; 74 | if (!mSticky && Math.abs(dy) > mTouchSlop || mSticky && dy < 0 && isTop()) { 75 | mLastedY = y; 76 | return true; 77 | } 78 | break; 79 | } 80 | return super.onInterceptTouchEvent(ev); 81 | } 82 | 83 | @Override 84 | public boolean onTouchEvent(MotionEvent event) { 85 | float y = event.getRawY(); 86 | switch (event.getActionMasked()) { 87 | case MotionEvent.ACTION_DOWN: 88 | mLastedY = y; 89 | return true; 90 | case MotionEvent.ACTION_MOVE: 91 | float dy = mLastedY - y; 92 | if (Math.abs(dy) > mTouchSlop && !mDraging) { 93 | mDraging = true; 94 | } 95 | if (mDraging) { 96 | setTopMargin((int) (getTopMargin() - dy)); 97 | mLastedY = y; 98 | } 99 | return true; 100 | case MotionEvent.ACTION_UP: 101 | if (mHeader != null && mHeader.isScrolling()) { 102 | //do nothing. 103 | } else { 104 | fling(); 105 | } 106 | break; 107 | } 108 | return super.onTouchEvent(event); 109 | } 110 | 111 | /** 112 | * 使header坍塌 113 | */ 114 | public void collapse() { 115 | startFlingAnimation(getTopMargin(), mMinMargin); 116 | } 117 | 118 | private void fling() { 119 | start = getTopMargin(); 120 | if (mCollapsed) { 121 | if (Math.abs(getTopMargin() - mMinMargin) < mThreshold) { 122 | end = mMinMargin; 123 | } else { 124 | end = mMaxMargin; 125 | } 126 | } else { 127 | if (getScrollDistance() < mThreshold) { 128 | end = mMaxMargin; 129 | } else { 130 | end = mMinMargin; 131 | } 132 | } 133 | startFlingAnimation(start, end); 134 | } 135 | 136 | @Override 137 | public void onHeaderCollapse() { 138 | startFlingAnimation(getTopMargin(), mMinMargin); 139 | } 140 | 141 | private void startFlingAnimation(int start, int end) { 142 | if (mAnimator == null || !mAnimator.isRunning()) { 143 | mAnimator = ObjectAnimator.ofInt(this, "TopMargin", start, end); 144 | mAnimator.setDuration(300); 145 | mAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); 146 | mAnimator.start(); 147 | } 148 | } 149 | 150 | @Override 151 | public void onHeaderHeightChange(int height) { 152 | initMargin(height); 153 | } 154 | 155 | public void setTopMargin(int topMargin) { 156 | getMarginLayoutParams().topMargin = topMargin; 157 | 158 | if (mListener != null) { 159 | mListener.onScroll(getScrollDistance()); 160 | } 161 | 162 | if (getTopMargin() >= mHeader.getBottom()) { 163 | mCollapsed = false; 164 | getMarginLayoutParams().topMargin = mHeader.getBottom(); 165 | } 166 | if (getTopMargin() <= mMinMargin) { 167 | mSticky = true; 168 | mCollapsed = true; 169 | getMarginLayoutParams().topMargin = mMinMargin; 170 | } else { 171 | mSticky = false; 172 | } 173 | if (mHeader != null) { 174 | mHeader.setTopMargin((int) (-(mMaxMargin - getTopMargin()) * mFactor)); 175 | } 176 | requestLayout(); 177 | } 178 | 179 | private int getScrollDistance() { 180 | return mMaxMargin - getTopMargin(); 181 | } 182 | 183 | public int getThreshold() { 184 | return mThreshold; 185 | } 186 | 187 | public int getMinMargin() { 188 | return mMinMargin; 189 | } 190 | 191 | public int getMaxMargin() { 192 | return mMaxMargin; 193 | } 194 | 195 | public int getTopMargin() { 196 | return getMarginLayoutParams().topMargin; 197 | } 198 | 199 | public void setFactor(float factor) { 200 | mFactor = factor; 201 | } 202 | 203 | public float getFactor() { 204 | return mFactor; 205 | } 206 | 207 | private MarginLayoutParams getMarginLayoutParams() { 208 | return (MarginLayoutParams) getLayoutParams(); 209 | } 210 | 211 | /** 212 | * 设置header 213 | * 214 | * @param header ExpandableHeader 215 | */ 216 | public void setUpWithHeader(ExpandableHeader header) { 217 | if (header == null) { 218 | throw new RuntimeException("The ExpandableHeader is null!"); 219 | } 220 | mHeader = header; 221 | mHeader.setCollapseListener(this); 222 | initMargin(mHeader.getBottom()); 223 | } 224 | 225 | private void initMargin(int topMargin) { 226 | getMarginLayoutParams().topMargin = topMargin; 227 | mMaxMargin = topMargin; 228 | requestLayout(); 229 | } 230 | 231 | public void setThreshold(int threshold) { 232 | mThreshold = threshold; 233 | } 234 | 235 | public void setMinMargin(int minMargin) { 236 | mMinMargin = minMargin; 237 | } 238 | 239 | public boolean isCollapsed() { 240 | return mCollapsed; 241 | } 242 | 243 | private boolean isTop() { 244 | View scrollableView = getChildAt(0); 245 | if (scrollableView == null) { 246 | return true; 247 | } 248 | if (scrollableView instanceof AdapterView) { 249 | return isAdapterViewTop((AdapterView) scrollableView); 250 | } 251 | if (scrollableView instanceof ScrollView) { 252 | return isScrollViewTop((ScrollView) scrollableView); 253 | } 254 | if (scrollableView instanceof RecyclerView) { 255 | return isRecyclerViewTop((RecyclerView) scrollableView); 256 | } 257 | if (scrollableView instanceof WebView) { 258 | return isWebViewTop((WebView) scrollableView); 259 | } 260 | if (scrollableView instanceof NestedScrollView){ 261 | return isNestScrollViewTop((NestedScrollView) scrollableView); 262 | } 263 | return true; 264 | } 265 | 266 | private boolean isAdapterViewTop(AdapterView adapterView) { 267 | if (adapterView != null) { 268 | int firstVisiblePosition = adapterView.getFirstVisiblePosition(); 269 | View childAt = adapterView.getChildAt(0); 270 | if (childAt == null || (firstVisiblePosition == 0 && childAt.getTop() == 0)) { 271 | return true; 272 | } 273 | } 274 | return false; 275 | } 276 | 277 | private boolean isScrollViewTop(ScrollView scrollView) { 278 | if (scrollView != null) { 279 | int scrollViewY = scrollView.getScrollY(); 280 | return scrollViewY <= 0; 281 | } 282 | return false; 283 | } 284 | 285 | private boolean isNestScrollViewTop(NestedScrollView scrollView){ 286 | if (scrollView != null) { 287 | int scrollViewY = scrollView.getScrollY(); 288 | return scrollViewY <= 0; 289 | } 290 | return false; 291 | } 292 | 293 | private boolean isWebViewTop(WebView scrollView) { 294 | if (scrollView != null) { 295 | int scrollViewY = scrollView.getScrollY(); 296 | return scrollViewY <= 0; 297 | } 298 | return false; 299 | } 300 | 301 | private boolean isRecyclerViewTop(RecyclerView recyclerView) { 302 | if (recyclerView != null) { 303 | RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); 304 | if (layoutManager instanceof LinearLayoutManager) { 305 | int firstVisibleItemPosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition(); 306 | View childAt = recyclerView.getChildAt(0); 307 | if (childAt == null || (firstVisibleItemPosition == 0 && childAt.getTop() == 0)) { 308 | return true; 309 | } 310 | } 311 | } 312 | return false; 313 | } 314 | 315 | public void setOnLayoutScrollListener(OnLayoutScrollListener listener) { 316 | mListener = listener; 317 | } 318 | 319 | public interface OnLayoutScrollListener { 320 | void onScroll(int scrollDistance); 321 | } 322 | } 323 | -------------------------------------------------------------------------------- /library/src/main/res/values/attr.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Library 3 | 4 | -------------------------------------------------------------------------------- /library/src/test/java/com/licrafter/exp/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.licrafter.exp; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "com.licrafter.sample" 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 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(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.squareup.picasso:picasso:2.5.2' 28 | compile 'com.android.support:design:25.1.0' 29 | compile 'com.android.support:appcompat-v7:25.1.0' 30 | testCompile 'junit:junit:4.12' 31 | compile project(path: ':library') 32 | } 33 | -------------------------------------------------------------------------------- /sample/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 /usr/local/Cellar/android-sdk-macosx/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 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/licrafter/sample/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.licrafter.sample; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.licrafter.expandablelayout", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /sample/src/main/java/com/licrafter/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.licrafter.sample; 2 | 3 | import android.content.Context; 4 | import android.os.Build; 5 | import android.support.v4.view.PagerAdapter; 6 | import android.support.v4.view.ViewPager; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.os.Bundle; 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.support.v7.widget.RecyclerView; 11 | import android.support.v7.widget.Toolbar; 12 | import android.view.LayoutInflater; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.widget.ImageView; 16 | import android.widget.LinearLayout; 17 | import android.widget.TextView; 18 | import android.widget.Toast; 19 | 20 | import com.licrafter.exp.ExpandableHeader; 21 | import com.licrafter.exp.ExpandableLayout; 22 | import com.licrafter.sample.repo.ImageModel; 23 | import com.licrafter.sample.repo.Repo; 24 | import com.licrafter.sample.utils.Utils; 25 | import com.squareup.picasso.Picasso; 26 | 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | 30 | public class MainActivity extends AppCompatActivity { 31 | 32 | private ExpandableHeader mExpHeader; 33 | private ExpandableLayout mExpLayout; 34 | private ViewPager mHeaderPager; 35 | private RecyclerView mRecyclerview; 36 | private Toolbar mToolbar; 37 | 38 | private LinearLayout mToolbarLayout; 39 | private View mStatusView; 40 | 41 | private List banners = new ArrayList<>(); 42 | private List fullHeights = new ArrayList<>(); 43 | 44 | @Override 45 | protected void onCreate(Bundle savedInstanceState) { 46 | super.onCreate(savedInstanceState); 47 | setContentView(R.layout.activity_main); 48 | Utils.setTranslucentMode(this); 49 | Repo.initRepo(); 50 | mToolbar = (Toolbar) findViewById(R.id.toolbar); 51 | mToolbarLayout = (LinearLayout) findViewById(R.id.toolbarLayout); 52 | mStatusView = findViewById(R.id.statusBar); 53 | mExpHeader = (ExpandableHeader) findViewById(R.id.exp_header); 54 | mExpLayout = (ExpandableLayout) findViewById(R.id.exp_layout); 55 | mHeaderPager = (ViewPager) findViewById(R.id.viewPager); 56 | mRecyclerview = (RecyclerView) findViewById(R.id.recyclerview); 57 | setSupportActionBar(mToolbar); 58 | mToolbarLayout.setAlpha(0); 59 | mRecyclerview.setLayoutManager(new LinearLayoutManager(this)); 60 | mRecyclerview.setAdapter(new SampleAdapter()); 61 | mToolbar.post(new Runnable() { 62 | @Override 63 | public void run() { 64 | mExpLayout.setMinMargin(mToolbar.getHeight() + mStatusView.getHeight()); 65 | mExpLayout.setThreshold(mToolbar.getHeight() + mStatusView.getHeight()); 66 | mExpHeader.setThreshold(mToolbar.getHeight() + mStatusView.getHeight()); 67 | } 68 | }); 69 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 70 | mStatusView.getLayoutParams().height = Utils.getStatusBarHeight(this); 71 | } 72 | mExpLayout.setUpWithHeader(mExpHeader); 73 | mExpLayout.setOnLayoutScrollListener(new ExpandableLayout.OnLayoutScrollListener() { 74 | @Override 75 | public void onScroll(int scrollDistance) { 76 | changeToolbar(mExpLayout.isCollapsed(), scrollDistance); 77 | } 78 | }); 79 | loadData(); 80 | mHeaderPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { 81 | @Override 82 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 83 | if (position == fullHeights.size() - 1) { 84 | return; 85 | } 86 | //计算ViewPager现在应该的高度,heights[]表示页面高度的数组。 87 | int height = (int) ((fullHeights.get(position) == 0 ? fullHeights.get(0) : fullHeights.get(position)) 88 | * (1 - positionOffset) + 89 | (fullHeights.get(position + 1) == 0 ? fullHeights.get(0) : fullHeights.get(position + 1)) 90 | * positionOffset); 91 | mExpHeader.setHeight(height); 92 | } 93 | 94 | @Override 95 | public void onPageSelected(int position) { 96 | } 97 | 98 | @Override 99 | public void onPageScrollStateChanged(int state) { 100 | 101 | } 102 | }); 103 | } 104 | 105 | private void loadData(){ 106 | mToolbar.postDelayed(new Runnable() { 107 | @Override 108 | public void run() { 109 | banners.addAll(Repo.data); 110 | for (ImageModel model : banners) { 111 | fullHeights.add(Utils.getDisplayWidth(MainActivity.this) * model.getHeight() / model.getWidth()); 112 | } 113 | mHeaderPager.setAdapter(new BannerPagerAdapter(getApplicationContext())); 114 | mExpHeader.setHeight(fullHeights.get(0)); 115 | } 116 | },1000); 117 | } 118 | 119 | public void changeToolbar(boolean collapse, int distance) { 120 | float alpha = (float) (mExpLayout.getThreshold() - mExpLayout.getTopMargin() + mExpLayout.getMinMargin()) / mExpLayout.getThreshold(); 121 | setToolbarAlpha(alpha < 0 ? 0 : alpha); 122 | } 123 | 124 | public void setToolbarAlpha(float alpha) { 125 | mToolbarLayout.setAlpha(alpha); 126 | } 127 | 128 | public class SampleAdapter extends RecyclerView.Adapter { 129 | 130 | @Override 131 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 132 | final SampleHolder holder = new SampleHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_sample, parent, false)); 133 | holder.title.setOnClickListener(new View.OnClickListener() { 134 | @Override 135 | public void onClick(View v) { 136 | Toast.makeText(MainActivity.this, "点击 position " + holder.getAdapterPosition(), Toast.LENGTH_SHORT).show(); 137 | } 138 | }); 139 | return holder; 140 | } 141 | 142 | @Override 143 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 144 | if (holder instanceof SampleHolder) { 145 | ((SampleHolder) holder).title.setText("item-" + position); 146 | } 147 | } 148 | 149 | @Override 150 | public int getItemCount() { 151 | return 40; 152 | } 153 | } 154 | 155 | class SampleHolder extends RecyclerView.ViewHolder { 156 | 157 | TextView title; 158 | 159 | public SampleHolder(View itemView) { 160 | super(itemView); 161 | title = (TextView) itemView.findViewById(R.id.title); 162 | } 163 | } 164 | 165 | class BannerPagerAdapter extends PagerAdapter { 166 | 167 | private LayoutInflater inflater; 168 | 169 | public BannerPagerAdapter(Context context) { 170 | this.inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE); 171 | 172 | } 173 | 174 | @Override 175 | public int getCount() { 176 | return 1; 177 | } 178 | 179 | @Override 180 | public boolean isViewFromObject(View view, Object object) { 181 | return view == object; 182 | } 183 | 184 | @Override 185 | public Object instantiateItem(ViewGroup container, int position) { 186 | ImageView imageView = (ImageView) inflater.inflate(R.layout.layout_banner_image, container, false); 187 | Picasso.with(container.getContext()).load(banners.get(position).getUrl()).into(imageView); 188 | container.addView(imageView); 189 | return imageView; 190 | } 191 | 192 | @Override 193 | public void destroyItem(ViewGroup container, int position, Object object) { 194 | container.removeView((View) object); 195 | } 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /sample/src/main/java/com/licrafter/sample/repo/ImageModel.java: -------------------------------------------------------------------------------- 1 | package com.licrafter.sample.repo; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * author: shell 7 | * date 2017/1/16 上午11:38 8 | **/ 9 | public class ImageModel implements Serializable{ 10 | 11 | private String url; 12 | private int height; 13 | private int width; 14 | 15 | public ImageModel(String url, int width, int height) { 16 | this.url = url; 17 | this.height = height; 18 | this.width = width; 19 | } 20 | 21 | public String getUrl() { 22 | return url; 23 | } 24 | 25 | public void setUrl(String url) { 26 | this.url = url; 27 | } 28 | 29 | public int getHeight() { 30 | return height; 31 | } 32 | 33 | public void setHeight(int height) { 34 | this.height = height; 35 | } 36 | 37 | public int getWidth() { 38 | return width; 39 | } 40 | 41 | public void setWidth(int width) { 42 | this.width = width; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /sample/src/main/java/com/licrafter/sample/repo/Repo.java: -------------------------------------------------------------------------------- 1 | package com.licrafter.sample.repo; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * author: shell 8 | * date 2017/1/17 上午9:43 9 | **/ 10 | public class Repo { 11 | 12 | public static List data = new ArrayList<>(); 13 | 14 | public static void initRepo() { 15 | data.add(new ImageModel("http://ci.xiaohongshu.com/2cc966e2-eed0-455c-be10-e1377a99b73c@r_1280w_1280h.jpg", 1280, 1280)); 16 | //data.add(new ImageModel("http://ci.xiaohongshu.com/c09d083b-2464-4cbe-9219-5210edaff64e@r_1280w_1280h.jpg", 960, 1280)); 17 | //data.add(new ImageModel("http://ci.xiaohongshu.com/206222a6-2de4-40f4-a002-654968478e59@r_1280w_1280h.jpg", 1024, 1280)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /sample/src/main/java/com/licrafter/sample/utils/Utils.java: -------------------------------------------------------------------------------- 1 | package com.licrafter.sample.utils; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.graphics.Color; 6 | import android.graphics.Point; 7 | import android.os.Build; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.view.View; 10 | import android.view.Window; 11 | import android.view.WindowManager; 12 | 13 | /** 14 | * author: shell 15 | * date 2017/1/16 下午5:04 16 | **/ 17 | public class Utils { 18 | 19 | public static int getDisplayWidth(AppCompatActivity context) { 20 | Point point = new Point(); 21 | context.getWindowManager().getDefaultDisplay().getSize(point); 22 | return point.x; 23 | } 24 | 25 | public static int getStatusBarHeight(Context context) { 26 | try { 27 | int result = 0; 28 | int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); 29 | if (resourceId > 0) { 30 | result = context.getResources().getDimensionPixelSize(resourceId); 31 | } 32 | return result; 33 | } catch (Exception e) { 34 | e.printStackTrace(); 35 | } 36 | return 0; 37 | } 38 | 39 | public static void setTranslucentMode(Activity activity) { 40 | Window window = activity.getWindow(); 41 | View decorView = window.getDecorView(); 42 | if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { 43 | window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 44 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 45 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 46 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 47 | decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); 48 | window.setStatusBarColor(Color.TRANSPARENT); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 20 | 21 | 22 | 26 | 27 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/fragment_pager.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/include_toolbar.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 | 23 | 24 | 29 | 30 | 31 | 35 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_sample.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 20 | 21 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/layout_banner_image.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/layout_toolar_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 21 | 22 | 27 | 28 | 29 | 33 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/layout_toolbar_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 21 | 22 | 27 | 28 | 29 | 33 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shellljx/ExpandableLayout/65724dd4a587b499f236deae9cd3651e5f6413e1/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shellljx/ExpandableLayout/65724dd4a587b499f236deae9cd3651e5f6413e1/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shellljx/ExpandableLayout/65724dd4a587b499f236deae9cd3651e5f6413e1/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_action_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shellljx/ExpandableLayout/65724dd4a587b499f236deae9cd3651e5f6413e1/sample/src/main/res/mipmap-xxhdpi/ic_action_back.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shellljx/ExpandableLayout/65724dd4a587b499f236deae9cd3651e5f6413e1/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shellljx/ExpandableLayout/65724dd4a587b499f236deae9cd3651e5f6413e1/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ExpandableLayout 3 | 4 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sample/src/test/java/com/licrafter/sample/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.licrafter.sample; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':library' 2 | --------------------------------------------------------------------------------