├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── colors.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── icon_tour_map.png
│ │ │ │ ├── icon_back_white.png
│ │ │ │ ├── icon_tour_label.png
│ │ │ │ ├── icon_tour_loved.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ ├── icon_tour_forward.png
│ │ │ │ ├── icon_tour_location.png
│ │ │ │ └── icon_tour_background.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── drawable
│ │ │ │ ├── bg_cardview_white_top.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── include_main_top.xml
│ │ │ │ └── include_main_content.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── wbb
│ │ │ └── bottomslide
│ │ │ ├── DensityUtils.kt
│ │ │ └── MainActivity.kt
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── wbb
│ │ │ └── bottomslide
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── wbb
│ │ └── bottomslide
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── screenshot
└── 8518082-48e41f9026b4db59.gif
├── gradle.properties
├── .gitignore
├── gradlew.bat
├── gradlew
└── README.md
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BottomSlide
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weibindev/BottomSlide/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/screenshot/8518082-48e41f9026b4db59.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weibindev/BottomSlide/HEAD/screenshot/8518082-48e41f9026b4db59.gif
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weibindev/BottomSlide/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weibindev/BottomSlide/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weibindev/BottomSlide/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/icon_tour_map.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weibindev/BottomSlide/HEAD/app/src/main/res/mipmap-xhdpi/icon_tour_map.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weibindev/BottomSlide/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weibindev/BottomSlide/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weibindev/BottomSlide/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weibindev/BottomSlide/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/icon_back_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weibindev/BottomSlide/HEAD/app/src/main/res/mipmap-xhdpi/icon_back_white.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/icon_tour_label.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weibindev/BottomSlide/HEAD/app/src/main/res/mipmap-xhdpi/icon_tour_label.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/icon_tour_loved.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weibindev/BottomSlide/HEAD/app/src/main/res/mipmap-xhdpi/icon_tour_loved.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weibindev/BottomSlide/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/icon_tour_forward.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weibindev/BottomSlide/HEAD/app/src/main/res/mipmap-xhdpi/icon_tour_forward.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/icon_tour_location.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weibindev/BottomSlide/HEAD/app/src/main/res/mipmap-xhdpi/icon_tour_location.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weibindev/BottomSlide/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weibindev/BottomSlide/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/icon_tour_background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weibindev/BottomSlide/HEAD/app/src/main/res/mipmap-xhdpi/icon_tour_background.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_cardview_white_top.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/wbb/bottomslide/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.wbb.bottomslide
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 | #FFFFFF
8 | #666
9 | #ccc
10 | #FFD328
11 |
12 | #F2F2F2
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/wbb/bottomslide/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.wbb.bottomslide
2 |
3 | import android.support.test.InstrumentationRegistry
4 | import android.support.test.runner.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getTargetContext()
22 | assertEquals("com.wbb.bottomslide", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # Kotlin code style for this project: "official" or "obsolete":
15 | kotlin.code.style=official
16 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion 28
9 | defaultConfig {
10 | applicationId "com.wbb.bottomslide"
11 | minSdkVersion 21
12 | targetSdkVersion 28
13 | versionCode 1
14 | versionName "1.0"
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | implementation fileTree(dir: 'libs', include: ['*.jar'])
27 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
28 | implementation 'com.android.support:appcompat-v7:28.0.0'
29 | implementation 'com.android.support:design:28.0.0'
30 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
31 | testImplementation 'junit:junit:4.12'
32 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wbb/bottomslide/DensityUtils.kt:
--------------------------------------------------------------------------------
1 | package com.wbb.bottomslide
2 |
3 | import android.content.Context
4 | import android.util.TypedValue
5 |
6 | /**
7 | * 屏幕密度像素工具类
8 | * @author vico
9 | * @date 2019/1/23
10 | * email: 1005078384@qq.com
11 | */
12 | object DensityUtils {
13 | /**
14 | * dp转px
15 | */
16 | fun dp2px(context: Context, dpVal: Float): Int {
17 | return TypedValue.applyDimension(
18 | TypedValue.COMPLEX_UNIT_DIP,
19 | dpVal, context.resources.displayMetrics
20 | ).toInt()
21 | }
22 |
23 | /**
24 | * sp转px
25 | */
26 | fun sp2px(context: Context, spVal: Float): Int {
27 | return TypedValue.applyDimension(
28 | TypedValue.COMPLEX_UNIT_SP,
29 | spVal, context.resources.displayMetrics
30 | ).toInt()
31 | }
32 |
33 | /**
34 | * px转dp
35 | */
36 | fun px2dp(context: Context, pxVal: Float): Float {
37 | val scale = context.resources.displayMetrics.density;
38 | return (pxVal / scale)
39 | }
40 |
41 | /**
42 | * px转sp
43 | */
44 | fun px2sp(context: Context, pxVal: Float): Float {
45 | val scale = context.resources.displayMetrics.scaledDensity
46 | return pxVal / scale
47 | }
48 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches/build_file_checksums.ser
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | .DS_Store
9 | /build
10 | /captures
11 | .externalNativeBuild
12 | ### Example user template template
13 | ### Example user template
14 |
15 | # IntelliJ project files
16 | .idea
17 | *.iml
18 | out
19 | gen### Android template
20 | # Built application files
21 | *.apk
22 | *.ap_
23 |
24 | # Files for the ART/Dalvik VM
25 | *.dex
26 |
27 | # Java class files
28 | *.class
29 |
30 | # Generated files
31 | bin/
32 | gen/
33 | out/
34 |
35 | # Gradle files
36 | .gradle/
37 | build/
38 |
39 | # Local configuration file (sdk path, etc)
40 | local.properties
41 |
42 | # Proguard folder generated by Eclipse
43 | proguard/
44 |
45 | # Log Files
46 | *.log
47 |
48 | # Android Studio Navigation editor temp files
49 | .navigation/
50 |
51 | # Android Studio captures folder
52 | captures/
53 |
54 | # IntelliJ
55 | *.iml
56 | .idea/workspace.xml
57 | .idea/tasks.xml
58 | .idea/gradle.xml
59 | .idea/assetWizardSettings.xml
60 | .idea/dictionaries
61 | .idea/libraries
62 | .idea/caches
63 |
64 | # Keystore files
65 | # Uncomment the following line if you do not want to check your keystore files in.
66 | #*.jks
67 |
68 | # External native build folder generated in Android Studio 2.2 and later
69 | .externalNativeBuild
70 |
71 | # Google Services (e.g. APIs or Firebase)
72 | google-services.json
73 |
74 | # Freeline
75 | freeline.py
76 | freeline/
77 | freeline_project_description.json
78 |
79 | # fastlane
80 | fastlane/report.xml
81 | fastlane/Preview.html
82 | fastlane/screenshots
83 | fastlane/test_output
84 | fastlane/readme.md
85 |
86 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/include_main_top.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
27 |
28 |
38 |
39 |
49 |
50 |
51 |
57 |
58 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
10 |
12 |
14 |
16 |
18 |
20 |
22 |
24 |
26 |
28 |
30 |
32 |
34 |
36 |
38 |
40 |
42 |
44 |
46 |
48 |
50 |
52 |
54 |
56 |
58 |
60 |
62 |
64 |
66 |
68 |
70 |
72 |
74 |
75 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wbb/bottomslide/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.wbb.bottomslide
2 |
3 | import android.animation.ObjectAnimator
4 | import android.graphics.Color
5 | import android.os.Bundle
6 | import android.os.Handler
7 | import android.support.constraint.ConstraintLayout
8 | import android.support.design.widget.BottomSheetBehavior
9 | import android.support.design.widget.TabLayout
10 | import android.support.v7.app.AppCompatActivity
11 | import android.util.Log
12 | import android.util.TypedValue
13 | import android.view.View
14 | import android.widget.Toast
15 | import kotlinx.android.synthetic.main.include_main_content.*
16 | import kotlinx.android.synthetic.main.include_main_top.*
17 |
18 | /**
19 | * @author vico
20 | * @date 2019/1/23
21 | * email: 1005078384@qq.com
22 | */
23 | class MainActivity : AppCompatActivity() {
24 |
25 | private var heightPixels: Int = 0
26 | private var peekHeight: Int = 0
27 | private var marginTop: Int = 0
28 | private var offsetDistance: Int = 0
29 | private lateinit var mHandler: Handler
30 |
31 | companion object {
32 | const val TAG = "MainActivity.class"
33 | }
34 |
35 | override fun onCreate(savedInstanceState: Bundle?) {
36 | super.onCreate(savedInstanceState)
37 | setContentView(R.layout.activity_main)
38 | //初始屏幕相关的参数
39 | initSystem()
40 | initView()
41 | initBehavior()
42 | }
43 |
44 | private fun initBehavior() {
45 | val behavior = BottomSheetBehavior.from(nestedScrollView)
46 | behavior.isHideable = true
47 | behavior.state = BottomSheetBehavior.STATE_HIDDEN
48 | behavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
49 |
50 | override fun onStateChanged(bottomSheet: View, newState: Int) {
51 | val layoutParams = bottomSheet.layoutParams
52 | //如果控件本身的Height值就小于返回按钮的高度,就不用做处理
53 | if (bottomSheet.height > heightPixels - marginTop) {
54 | //屏幕高度减去marinTop作为控件的Height
55 | layoutParams.height = heightPixels - marginTop
56 | bottomSheet.layoutParams = layoutParams
57 | }
58 | }
59 |
60 | override fun onSlide(bottomSheet: View, slideOffset: Float) {
61 | var distance: Float = 0F;
62 | /**
63 | * slideOffset为底部的新偏移量,值在[-1,1]范围内。当BottomSheetBehavior处于折叠(STATE_COLLAPSED)和
64 | * 展开(STATE_EXPANDED)状态之间时,它的值始终在[0,1]范围内,向上移动趋近于1,向下区间于0。[-1,0]处于
65 | * 隐藏状态(STATE_HIDDEN)和折叠状态(STATE_COLLAPSED)之间。
66 | */
67 |
68 | //这里的BottomSheetBehavior初始化完成后,界面设置始终可见,所以不用考虑[-1,0]区间
69 | //色差值变化->其实是遮罩的透明度变化,拖拽至最高,顶部成半透明色
70 | maskView.alpha = slideOffset
71 | //offsetDistance是initSystem()中获得的,是返回按钮至根布局的距离
72 | distance = offsetDistance * slideOffset
73 | //当BottomSheetBehavior由隐藏状态变为折叠状态(即gif图开始的由底部滑出至设置的最小高度)
74 | //slide在[-1,0]的区间内,不加判断会出现顶部布局向下偏移的情况。
75 | if (distance > 0) {
76 | constraint.translationY = -distance
77 | }
78 |
79 | Log.i(
80 | TAG,
81 | String.format(
82 | "slideOffset -->>> %s bottomSheet.getHeight() -->>> %s heightPixels -->>> %s",
83 | slideOffset,
84 | bottomSheet.height,
85 | heightPixels
86 | )
87 | )
88 | Log.i(TAG, String.format("distance -->>> %s", distance))
89 | }
90 |
91 | })
92 | mHandler.postDelayed({
93 | behavior.isHideable = false
94 | behavior.state = BottomSheetBehavior.STATE_COLLAPSED
95 | behavior.peekHeight = peekHeight
96 | ObjectAnimator.ofFloat(nestedScrollView, "alpha", 0f, 1f).setDuration(500).start()
97 | }, 200)
98 | }
99 |
100 | private fun initView() {
101 | tabLayout.tabMode = TabLayout.MODE_SCROLLABLE
102 | tabLayout.addTab(tabLayout.newTab().setText("费用说明"))
103 | tabLayout.addTab(tabLayout.newTab().setText("预定须知"))
104 | tabLayout.addTab(tabLayout.newTab().setText("退款政策"))
105 | tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
106 | override fun onTabReselected(tab: TabLayout.Tab) {
107 |
108 | }
109 |
110 | override fun onTabUnselected(tab: TabLayout.Tab) {
111 |
112 | }
113 |
114 | override fun onTabSelected(tab: TabLayout.Tab) {
115 | when (tab.position) {
116 | 0 -> frameLayout.setBackgroundColor(Color.parseColor("#ff0000"))
117 | 1 -> frameLayout.setBackgroundColor(Color.parseColor("#0000ff"))
118 | 2 -> frameLayout.setBackgroundColor(Color.parseColor("#00ff00"))
119 | }
120 | }
121 | })
122 | imageView.setOnClickListener { finish() }
123 | imageView2.setOnClickListener { Toast.makeText(this, "转发", Toast.LENGTH_SHORT).show() }
124 | imageView3.setOnClickListener { Toast.makeText(this, "收藏", Toast.LENGTH_SHORT).show() }
125 | mHandler = Handler()
126 | }
127 |
128 | private fun initSystem() {
129 | //获取屏幕高度
130 | heightPixels = resources.displayMetrics.heightPixels
131 | Log.i(TAG, "heightPixels: $heightPixels")
132 |
133 | val behaviorHeight = DensityUtils.px2dp(this, (heightPixels / 2).toFloat())
134 | peekHeight =
135 | TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, behaviorHeight, resources.displayMetrics).toInt()
136 | Log.i(TAG, "peekHeight: $peekHeight")
137 |
138 | imageView.post {
139 | val lp = imageView.layoutParams as ConstraintLayout.LayoutParams
140 |
141 | //获取状态栏高度
142 | var statusBarHeight = 0
143 | val resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android")
144 | if (resourceId > 0) {
145 | statusBarHeight = resources.getDimensionPixelSize(resourceId)
146 | }
147 | //返回按钮至屏幕顶部的高度
148 | marginTop = imageView.height + lp.topMargin + lp.bottomMargin / 2 + statusBarHeight
149 | //返回按钮至根布局的距离
150 | offsetDistance = lp.topMargin
151 | }
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/include_main_content.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
17 |
18 |
31 |
32 |
38 |
39 |
40 |
41 |
55 |
56 |
67 |
68 |
82 |
83 |
94 |
95 |
96 |
110 |
111 |
112 |
126 |
127 |
134 |
135 |
144 |
145 |
153 |
154 |
166 |
167 |
174 |
175 |
187 |
188 |
195 |
196 |
197 |
198 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BottomSlide
2 | 使用BottomSheetBehavior实现仿美团拖拽效果
3 | > 前几天看到一片文章,文章的标题是[Android 仿美团拖拽效果](https://www.jianshu.com/p/92180b45aaf7),抱着好奇心去看了下,效果确实不错,但实现过程较为复杂。用原生的CoordinatorLayout+BottomSheetBehavior可以快速的实现这一效果,所以心血来潮打算水一篇文章。
demo地址:[https://github.com/weibindev/BottomSlide](https://github.com/weibindev/BottomSlide)
4 |
5 | `注:`本文的所有图文素材均来自[https://www.jianshu.com/p/92180b45aaf7](https://www.jianshu.com/p/92180b45aaf7)
6 |
7 | 先来看下成品效果:
8 |
9 | 
10 |
11 | #### 实现思路分析:
12 | 1. 界面上可以分为两个部分:顶部部分包括一系列的图片和按钮控件;底部部分是用`NestedScrollView`包裹实现的界面,并且指定 `app:layout_behavior="@string/bottom_sheet_behavior"`。界面根布局采用`CoordinatorLayout`,与`BottomSheetBehavior`包装底部部分的布局实现拖拽。
13 | 2. 当界面初始化时,`BottomSheetBehavior`以淡入的方式平滑至设定的最小高度。在`BottomSheetBehavior`拖拽过程中,通过代码改变View的`layoutParams`属性使其达到所能拖拽的最大高度。
14 | 3. 除去底部部分初始化淡入的过程,其余时间顶部部分都会发生色差值和视图偏移的变化。
15 |
16 | #### 界面布局:
17 | `activity_main.xml`
18 | ```XML
19 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | ```
32 | `include_main_top.xml`
33 |
34 | ```XML
35 |
41 |
42 |
49 |
50 |
60 |
61 |
71 |
72 |
82 |
83 |
84 |
90 |
91 |
92 | ```
93 | `include_main_content.xml`
94 |
95 | ```XML
96 |
105 |
106 |
111 |
112 |
125 |
126 |
132 |
133 |
134 |
135 |
149 |
150 |
161 |
162 |
176 |
177 |
188 |
189 |
190 |
204 |
205 |
206 |
220 |
221 |
228 |
229 |
238 |
239 |
247 |
248 |
260 |
261 |
268 |
269 |
281 |
282 |
289 |
290 |
291 |
292 |
293 | ```
294 | 在` 0) {
336 | statusBarHeight = resources.getDimensionPixelSize(resourceId)
337 | }
338 | //返回按钮至屏幕顶部的高度
339 | marginTop = imageView.height + lp.topMargin + lp.bottomMargin / 2 + statusBarHeight
340 | //返回按钮至根布局的距离
341 | offsetDistance = lp.topMargin
342 | }
343 | ```
344 | 获取到`marginTop`后在`BottomSheetBehavior.BottomSheetCallback()`回调监听有底部工作的事件。
345 |
346 | `BottomSheetBehavior.BottomSheetCallback()`有两个事件
347 | ```Java
348 | //在拖动时调用
349 | void onSlide (View bottomSheet, float slideOffset)
350 | //在改变状态时调用
351 | void onStateChanged (View bottomSheet, int newState)
352 | ```
353 | 只要底部进行拖拽,其状态就会发生变化,所以在`onStateChanged (View bottomSheet, int newState)`做处理
354 | ```Kotlin
355 | behavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
356 |
357 | override fun onStateChanged(bottomSheet: View, newState: Int) {
358 | val layoutParams = bottomSheet.layoutParams
359 | //如果控件本身的Height值就小于返回按钮的高度,就不用做处理
360 | if (bottomSheet.height > heightPixels - marginTop) {
361 | //屏幕高度减去marinTop作为控件的Height
362 | layoutParams.height = heightPixels - marginTop
363 | bottomSheet.layoutParams = layoutParams
364 | }
365 | }
366 |
367 | override fun onSlide(bottomSheet: View, slideOffset: Float) {
368 |
369 | }
370 |
371 | })
372 | ```
373 | 相应的顶部色差值和偏移值的变化在另一个回调事件`void onSlide (View bottomSheet, float slideOffset) `中处理。
374 | ```Kotlin
375 | behavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
376 |
377 | override fun onStateChanged(bottomSheet: View, newState: Int) {
378 |
379 | }
380 |
381 | override fun onSlide(bottomSheet: View, slideOffset: Float) {
382 | var distance: Float = 0F;
383 | /**
384 | * slideOffset为底部的新偏移量,值在[-1,1]范围内。当BottomSheetBehavior处于折叠(STATE_COLLAPSED)和
385 | * 展开(STATE_EXPANDED)状态之间时,它的值始终在[0,1]范围内,向上移动趋近于1,向下区间于0。[-1,0]处于
386 | * 隐藏状态(STATE_HIDDEN)和折叠状态(STATE_COLLAPSED)之间。
387 | */
388 |
389 | //这里的BottomSheetBehavior初始化完成后,界面设置始终可见,所以不用考虑[-1,0]区间
390 | //色差值变化->其实是遮罩的透明度变化,拖拽至最高,顶部成半透明色
391 | maskView.alpha = slideOffset
392 | //offsetDistance是initSystem()中获得的,是返回按钮至根布局的距离
393 | distance = offsetDistance * slideOffset
394 | //当BottomSheetBehavior由隐藏状态变为折叠状态(即gif图开始的由底部滑出至设置的最小高度)
395 | //slide在[-1,0]的区间内,不加判断会出现顶部布局向下偏移的情况。
396 | if (distance > 0) {
397 | constraint.translationY = -distance
398 | }
399 | }
400 | })
401 | ```
402 | 最后还有`BottomSheetBehavior`的滑出效果:先设置`BottomSheetBehavior`的状态为隐藏,然后调用`Handler`的`postDelayed()`方法设置状态为折叠以及最小高度,当然再加一个属性动画,起到锦上添花的作用。
403 |
404 | 附上`MainActivity.kt`的全部代码
405 | ```Kotlin
406 | /**
407 | * @author vico
408 | * @date 2019/1/23
409 | * email: 1005078384@qq.com
410 | */
411 | class MainActivity : AppCompatActivity() {
412 |
413 | private var heightPixels: Int = 0
414 | private var peekHeight: Int = 0
415 | private var marginTop: Int = 0
416 | private var offsetDistance: Int = 0
417 | private lateinit var mHandler: Handler
418 |
419 | companion object {
420 | const val TAG = "MainActivity.class"
421 | }
422 |
423 | override fun onCreate(savedInstanceState: Bundle?) {
424 | super.onCreate(savedInstanceState)
425 | setContentView(R.layout.activity_main)
426 | //初始屏幕相关的参数
427 | initSystem()
428 | initView()
429 | initBehavior()
430 | }
431 |
432 | private fun initBehavior() {
433 | val behavior = BottomSheetBehavior.from(nestedScrollView)
434 | behavior.isHideable = true
435 | behavior.state = BottomSheetBehavior.STATE_HIDDEN
436 | behavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
437 |
438 | override fun onStateChanged(bottomSheet: View, newState: Int) {
439 | val layoutParams = bottomSheet.layoutParams
440 | //如果控件本身的Height值就小于返回按钮的高度,就不用做处理
441 | if (bottomSheet.height > heightPixels - marginTop) {
442 | //屏幕高度减去marinTop作为控件的Height
443 | layoutParams.height = heightPixels - marginTop
444 | bottomSheet.layoutParams = layoutParams
445 | }
446 | }
447 |
448 | override fun onSlide(bottomSheet: View, slideOffset: Float) {
449 | var distance: Float = 0F;
450 | /**
451 | * slideOffset为底部的新偏移量,值在[-1,1]范围内。当BottomSheetBehavior处于折叠(STATE_COLLAPSED)和
452 | * 展开(STATE_EXPANDED)状态之间时,它的值始终在[0,1]范围内,向上移动趋近于1,向下区间于0。[-1,0]处于
453 | * 隐藏状态(STATE_HIDDEN)和折叠状态(STATE_COLLAPSED)之间。
454 | */
455 |
456 | //这里的BottomSheetBehavior初始化完成后,界面设置始终可见,所以不用考虑[-1,0]区间
457 | //色差值变化->其实是遮罩的透明度变化,拖拽至最高,顶部成半透明色
458 | maskView.alpha = slideOffset
459 | //offsetDistance是initSystem()中获得的,是返回按钮至根布局的距离
460 | distance = offsetDistance * slideOffset
461 | //当BottomSheetBehavior由隐藏状态变为折叠状态(即gif图开始的由底部滑出至设置的最小高度)
462 | //slide在[-1,0]的区间内,不加判断会出现顶部布局向下偏移的情况。
463 | if (distance > 0) {
464 | constraint.translationY = -distance
465 | }
466 |
467 | Log.i(
468 | TAG,
469 | String.format(
470 | "slideOffset -->>> %s bottomSheet.getHeight() -->>> %s heightPixels -->>> %s",
471 | slideOffset,
472 | bottomSheet.height,
473 | heightPixels
474 | )
475 | )
476 | Log.i(TAG, String.format("distance -->>> %s", distance))
477 | }
478 |
479 | })
480 | mHandler.postDelayed({
481 | behavior.isHideable = false
482 | behavior.state = BottomSheetBehavior.STATE_COLLAPSED
483 | behavior.peekHeight = peekHeight
484 | ObjectAnimator.ofFloat(nestedScrollView, "alpha", 0f, 1f).setDuration(500).start()
485 | }, 200)
486 | }
487 |
488 | private fun initView() {
489 | tabLayout.tabMode = TabLayout.MODE_SCROLLABLE
490 | tabLayout.addTab(tabLayout.newTab().setText("费用说明"))
491 | tabLayout.addTab(tabLayout.newTab().setText("预定须知"))
492 | tabLayout.addTab(tabLayout.newTab().setText("退款政策"))
493 | tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
494 | override fun onTabReselected(tab: TabLayout.Tab) {
495 |
496 | }
497 |
498 | override fun onTabUnselected(tab: TabLayout.Tab) {
499 |
500 | }
501 |
502 | override fun onTabSelected(tab: TabLayout.Tab) {
503 | when (tab.position) {
504 | 0 -> frameLayout.setBackgroundColor(Color.parseColor("#ff0000"))
505 | 1 -> frameLayout.setBackgroundColor(Color.parseColor("#0000ff"))
506 | 2 -> frameLayout.setBackgroundColor(Color.parseColor("#00ff00"))
507 | }
508 | }
509 | })
510 | imageView.setOnClickListener { finish() }
511 | imageView2.setOnClickListener { Toast.makeText(this, "转发", Toast.LENGTH_SHORT).show() }
512 | imageView3.setOnClickListener { Toast.makeText(this, "收藏", Toast.LENGTH_SHORT).show() }
513 | mHandler = Handler()
514 | }
515 |
516 | private fun initSystem() {
517 | //获取屏幕高度
518 | heightPixels = resources.displayMetrics.heightPixels
519 | Log.i(TAG, "heightPixels: $heightPixels")
520 |
521 | val behaviorHeight = DensityUtils.px2dp(this, (heightPixels / 2).toFloat())
522 | peekHeight =
523 | TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, behaviorHeight, resources.displayMetrics).toInt()
524 | Log.i(TAG, "peekHeight: $peekHeight")
525 |
526 | imageView.post {
527 | val lp = imageView.layoutParams as ConstraintLayout.LayoutParams
528 |
529 | //获取状态栏高度
530 | var statusBarHeight = 0
531 | val resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android")
532 | if (resourceId > 0) {
533 | statusBarHeight = resources.getDimensionPixelSize(resourceId)
534 | }
535 | //返回按钮至屏幕顶部的高度
536 | marginTop = imageView.height + lp.topMargin + lp.bottomMargin / 2 + statusBarHeight
537 | //返回按钮至根布局的距离
538 | offsetDistance = lp.topMargin
539 | }
540 | }
541 | }
542 | ```
543 | #### 最后:
544 | 文章demo地址:[https://github.com/weibindev/BottomSlide](https://github.com/weibindev/BottomSlide)
545 |
546 | demo引用素材:
547 | [Android 仿美团拖拽效果](https://www.jianshu.com/p/92180b45aaf7)
548 |
549 | 参考文章:
550 | [Material Design系列-严振杰](https://blog.csdn.net/yanzhenjie1003/article/details/51946749)
551 |
--------------------------------------------------------------------------------