├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── timg.jpg
│ │ │ │ ├── back_black.png
│ │ │ │ ├── back_white.png
│ │ │ │ ├── image_home.png
│ │ │ │ ├── icon_position.png
│ │ │ │ ├── icon_prestige.png
│ │ │ │ ├── icon_arrow_right.png
│ │ │ │ ├── icon_menu_black.png
│ │ │ │ ├── icon_menu_white.png
│ │ │ │ ├── icon_friendliness.png
│ │ │ │ ├── icon_gender_woman.png
│ │ │ │ ├── icon_integral_red.png
│ │ │ │ └── icon_invite_friend.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── drawable
│ │ │ │ ├── stroke_black.xml
│ │ │ │ ├── stroke_blue.xml
│ │ │ │ ├── shape_gray_3.xml
│ │ │ │ ├── solid_corners_black_one.xml
│ │ │ │ ├── stroke_corners__black_one.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ ├── item_dynamic_article.xml
│ │ │ │ ├── item_mine_article.xml
│ │ │ │ ├── fragment_question.xml
│ │ │ │ ├── view_no_more.xml
│ │ │ │ ├── view_more.xml
│ │ │ │ ├── fragment_article.xml
│ │ │ │ ├── fragment_dynamic.xml
│ │ │ │ ├── item_mine_question.xml
│ │ │ │ ├── include_item_time.xml
│ │ │ │ ├── item_mine_answer.xml
│ │ │ │ ├── include_item_publish_article.xml
│ │ │ │ ├── item_dynamic_comment.xml
│ │ │ │ ├── item_dynamic_follow.xml
│ │ │ │ └── activity_main.xml
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── siberiadante
│ │ │ │ └── multiscrolldemo
│ │ │ │ ├── bean
│ │ │ │ ├── MineArticleBean.java
│ │ │ │ ├── MineQuestionBean.java
│ │ │ │ ├── MineDynamicBean.java
│ │ │ │ └── base
│ │ │ │ │ └── WrapBean.java
│ │ │ │ ├── util
│ │ │ │ ├── ScreenUtil.java
│ │ │ │ ├── DeviceUtil.java
│ │ │ │ └── StatusBarUtil.java
│ │ │ │ ├── adapter
│ │ │ │ ├── ComFragmentAdapter.java
│ │ │ │ ├── MineArticleAdapter.java
│ │ │ │ ├── MineQuestionAdapter.java
│ │ │ │ └── MineDynamicAdapter.java
│ │ │ │ ├── activity
│ │ │ │ ├── BaseActivity.java
│ │ │ │ └── MainActivity.java
│ │ │ │ ├── view
│ │ │ │ ├── ColorFlipPagerTitleView.java
│ │ │ │ ├── NormalDecoration.java
│ │ │ │ └── JudgeNestedScrollView.java
│ │ │ │ └── fragment
│ │ │ │ ├── base
│ │ │ │ ├── LazyFragment.java
│ │ │ │ └── BaseFragment.java
│ │ │ │ ├── ArticleFragment.java
│ │ │ │ ├── QuestionFragment.java
│ │ │ │ └── DynamicFragment.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── siberiadante
│ │ │ └── multiscrolldemo
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── siberiadante
│ │ └── multiscrolldemo
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── assets
└── GIF.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
└── misc.xml
├── README.md
├── gradle.properties
├── .gitignore
├── gradlew.bat
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/assets/GIF.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/assets/GIF.gif
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/timg.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/drawable-xhdpi/timg.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/back_black.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/drawable-xhdpi/back_black.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/back_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/drawable-xhdpi/back_white.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/image_home.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/drawable-xhdpi/image_home.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_position.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/drawable-xhdpi/icon_position.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_prestige.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/drawable-xhdpi/icon_prestige.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_arrow_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/drawable-xhdpi/icon_arrow_right.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_menu_black.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/drawable-xhdpi/icon_menu_black.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_menu_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/drawable-xhdpi/icon_menu_white.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/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/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_friendliness.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/drawable-xhdpi/icon_friendliness.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_gender_woman.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/drawable-xhdpi/icon_gender_woman.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_integral_red.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/drawable-xhdpi/icon_integral_red.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_invite_friend.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/drawable-xhdpi/icon_invite_friend.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/MultiScrollDemo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/stroke_black.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/stroke_blue.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/shape_gray_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/solid_corners_black_one.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Dec 17 17:52:04 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/stroke_corners__black_one.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_dynamic_article.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_mine_article.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_question.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
11 |
--------------------------------------------------------------------------------
/app/src/test/java/com/siberiadante/multiscrolldemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo;
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 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/bean/MineArticleBean.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.bean;
2 |
3 | /**
4 | * @Created SiberiaDante
5 | * @Describe:
6 | * @CreateTime: 2017/12/15
7 | * @UpDateTime:
8 | * @Email: 2654828081@qq.com
9 | * @GitHub: https://github.com/SiberiaDante
10 | */
11 |
12 | public class MineArticleBean {
13 | private String content;
14 |
15 | public String getContent() {
16 | return content;
17 | }
18 |
19 | public void setContent(String content) {
20 | this.content = content;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/bean/MineQuestionBean.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.bean;
2 |
3 | /**
4 | * @Created SiberiaDante
5 | * @Describe:
6 | * @CreateTime: 2017/12/15
7 | * @UpDateTime:
8 | * @Email: 2654828081@qq.com
9 | * @GitHub: https://github.com/SiberiaDante
10 | */
11 |
12 | public class MineQuestionBean {
13 | private String content;
14 |
15 | public String getContent() {
16 | return content;
17 | }
18 |
19 | public void setContent(String content) {
20 | this.content = content;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_no_more.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_more.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
13 |
14 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MultiScrollDemo
2 | 使用NestedScrollView+ViewPager+RecyclerView+SmartRefreshLayout打造酷炫下拉视差效果并解决各种滑动冲突
3 |
4 | 
5 |
6 | #### 详细说明:[博客地址:http://www.cnblogs.com/shen-hua/p/8052459.html](http://www.cnblogs.com/shen-hua/p/8052459.html)
7 | 实现了大概功能,没有过分的优化
8 |
9 | ## 优化修复
10 | * 华为虚拟键显示隐藏会导致测量的屏幕宽高发生变化,已修复并做了优化处理
11 | * 修复JudgeNestedScrollView的点击事件
12 | ## 其他方案
13 | * [不用涉及到各种冲突常规打造酷炫下拉视差效果SmartRefreshLayout+ViewPager+RecyclerView](https://github.com/LPTim/Stop-master)
14 | * [使用Design+自定义Behavior实现](https://github.com/JmStefanAndroid/EasyBehavior)
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_article.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_dynamic.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/bean/MineDynamicBean.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.bean;
2 |
3 | /**
4 | * @Created SiberiaDante
5 | * @Describe:
6 | * @CreateTime: 2017/12/17
7 | * @UpDateTime:
8 | * @Email: 2654828081@qq.com
9 | * @GitHub: https://github.com/SiberiaDante
10 | */
11 |
12 | public class MineDynamicBean {
13 | private String content;
14 | private int type;
15 |
16 | public int getType() {
17 | return type;
18 | }
19 |
20 | public void setType(int type) {
21 | this.type = type;
22 | }
23 |
24 | public String getContent() {
25 | return content;
26 | }
27 |
28 | public void setContent(String content) {
29 | this.content = content;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_mine_question.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MultiScrollDemo
3 | 签到
4 | 积分
5 | 日币
6 | 友好度
7 | 威望
8 | 编辑
9 | 兴趣标签
10 |
11 | 关注
12 | 编辑资料
13 | 粉丝
14 | 还没有人回答,抢一楼~
15 | 答
16 | 没有更多了
17 | 更多加载中...
18 |
19 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/bean/base/WrapBean.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.bean.base;
2 |
3 | /**
4 | * @Created SiberiaDante
5 | * @Describe:
6 | * @CreateTime: 2017/12/5
7 | * @UpDateTime:
8 | * @Email: 2654828081@qq.com
9 | * @GitHub: https://github.com/SiberiaDante
10 | */
11 |
12 | public class WrapBean {
13 | private int code;
14 | private String info;
15 | private T data;
16 |
17 | public int getCode() {
18 | return code;
19 | }
20 |
21 | public void setCode(int code) {
22 | this.code = code;
23 | }
24 |
25 | public String getInfo() {
26 | return info;
27 | }
28 |
29 | public void setInfo(String info) {
30 | this.info = info;
31 | }
32 |
33 | public T getData() {
34 | return data;
35 | }
36 |
37 | public void setData(T data) {
38 | this.data = data;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/siberiadante/multiscrolldemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo;
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 | * Instrumented 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.siberiadante.multiscrolldemo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 |
43 | # Keystore files
44 | *.jks
45 |
46 | # External native build folder generated in Android Studio 2.2 and later
47 | .externalNativeBuild
48 |
49 | # Google Services (e.g. APIs or Firebase)
50 | google-services.json
51 |
52 | # Freeline
53 | freeline.py
54 | freeline/
55 | freeline_project_description.json
56 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/util/ScreenUtil.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.util;
2 |
3 | import android.content.Context;
4 | import android.util.DisplayMetrics;
5 | import android.view.WindowManager;
6 |
7 | /**
8 | * @Created SiberiaDante
9 | * @Describe:
10 | * @CreateTime: 2017/12/18
11 | * @UpDateTime:
12 | * @Email: 2654828081@qq.com
13 | * @GitHub: https://github.com/SiberiaDante
14 | */
15 |
16 | public class ScreenUtil {
17 |
18 | /**
19 | * @return 获取屏幕的高 单位:px
20 | */
21 | public static int getScreenHeightPx(Context context) {
22 | WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
23 | DisplayMetrics dm = new DisplayMetrics();
24 | if (windowManager != null) {
25 | // windowManager.getDefaultDisplay().getMetrics(dm);
26 | windowManager.getDefaultDisplay().getRealMetrics(dm);
27 | return dm.heightPixels;
28 | }
29 | return 0;
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/adapter/ComFragmentAdapter.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.adapter;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentPagerAdapter;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * @Created SiberiaDante
11 | * @Describe:
12 | * @CreateTime: 2017/12/11
13 | * @UpDateTime:
14 | * @Email: 2654828081@qq.com
15 | * @GitHub: https://github.com/SiberiaDante
16 | */
17 |
18 | public class ComFragmentAdapter extends FragmentPagerAdapter {
19 |
20 | private List fragments;
21 |
22 | public ComFragmentAdapter(FragmentManager fm, List fragments) {
23 | super(fm);
24 | this.fragments = fragments;
25 | }
26 |
27 | @Override
28 | public Fragment getItem(int position) {
29 |
30 | return fragments.get(position);
31 | }
32 |
33 | @Override
34 | public int getCount() {
35 | return fragments != null ? fragments.size() : 0;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/include_item_time.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/activity/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.activity;
2 |
3 |
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v7.app.AppCompatActivity;
8 |
9 |
10 | import butterknife.ButterKnife;
11 |
12 | /**
13 | * @Created SiberiaDante
14 | * @Describe:
15 | * @CreateTime: 2017/12/5
16 | * @UpDateTime:
17 | * @Email: 2654828081@qq.com
18 | * @GitHub: https://github.com/SiberiaDante
19 | */
20 |
21 |
22 | public abstract class BaseActivity extends AppCompatActivity {
23 | public static final String TAG = BaseActivity.class.getSimpleName();
24 |
25 | @Override
26 | protected void onCreate(@Nullable Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | beforeSetContentView();
29 | setContentView(setLayoutId());
30 | ButterKnife.bind(this);
31 | initView(savedInstanceState);
32 | initData();
33 | }
34 |
35 | public void beforeSetContentView() {
36 | }
37 |
38 | public abstract int setLayoutId();
39 |
40 | public abstract void initView(Bundle savedInstanceState);
41 |
42 | public abstract void initData();
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
8 | #DEDEDE
9 |
10 | #242828
11 | #5b5b5b
12 | #ff3955
13 | #4277fb
14 | #ffffff
15 | #f8f8f8
16 | #f0f0f0
17 | #c6c6c6
18 | #888888
19 |
20 |
21 | #888888
22 | #c6c6c6
23 | #242828
24 | #ff3955
25 |
26 |
27 |
28 | #ff0112
29 | #a4a2a2
30 | #05f449
31 | #ffffff
32 | #000000
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_mine_answer.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
21 |
22 |
26 |
27 |
28 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/adapter/MineArticleAdapter.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.adapter;
2 |
3 |
4 | import android.content.Context;
5 | import android.view.ViewGroup;
6 | import android.widget.TextView;
7 |
8 | import com.jude.easyrecyclerview.adapter.BaseViewHolder;
9 | import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
10 | import com.siberiadante.multiscrolldemo.R;
11 | import com.siberiadante.multiscrolldemo.bean.MineArticleBean;
12 |
13 | /**
14 | * @Created SiberiaDante
15 | * @Describe:
16 | * @CreateTime: 2017/12/15
17 | * @UpDateTime:
18 | * @Email: 2654828081@qq.com
19 | * @GitHub: https://github.com/SiberiaDante
20 | */
21 |
22 | public class MineArticleAdapter extends RecyclerArrayAdapter {
23 | public MineArticleAdapter(Context context) {
24 | super(context);
25 | }
26 |
27 | @Override
28 | public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
29 | return new QuestionViewHolder(parent);
30 | }
31 |
32 | public class QuestionViewHolder extends BaseViewHolder {
33 |
34 | TextView textView;
35 |
36 | public QuestionViewHolder(ViewGroup parent) {
37 | super(parent, R.layout.item_mine_article);
38 | textView = $(R.id.tv_title);
39 | }
40 |
41 | @Override
42 | public void setData(MineArticleBean data) {
43 | super.setData(data);
44 | textView.setText(data.getContent());
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/adapter/MineQuestionAdapter.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.adapter;
2 |
3 |
4 | import android.content.Context;
5 | import android.view.ViewGroup;
6 | import android.widget.TextView;
7 |
8 | import com.jude.easyrecyclerview.adapter.BaseViewHolder;
9 | import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
10 | import com.siberiadante.multiscrolldemo.R;
11 | import com.siberiadante.multiscrolldemo.bean.MineQuestionBean;
12 |
13 | /**
14 | * @Created SiberiaDante
15 | * @Describe:
16 | * @CreateTime: 2017/12/15
17 | * @UpDateTime:
18 | * @Email: 2654828081@qq.com
19 | * @GitHub: https://github.com/SiberiaDante
20 | */
21 |
22 | public class MineQuestionAdapter extends RecyclerArrayAdapter {
23 | public MineQuestionAdapter(Context context) {
24 | super(context);
25 | }
26 |
27 | @Override
28 | public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
29 | return new QuestionViewHolder(parent);
30 | }
31 |
32 | public class QuestionViewHolder extends BaseViewHolder {
33 |
34 | TextView textView;
35 |
36 | public QuestionViewHolder(ViewGroup parent) {
37 | super(parent, R.layout.item_mine_question);
38 | textView = $(R.id.tv_title);
39 | }
40 |
41 | @Override
42 | public void setData(MineQuestionBean data) {
43 | super.setData(data);
44 | textView.setText(data.getContent());
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/view/ColorFlipPagerTitleView.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.view;
2 |
3 | import android.content.Context;
4 |
5 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;
6 |
7 | /**
8 | * Created by hackware on 2016/7/24.
9 | */
10 |
11 | public class ColorFlipPagerTitleView extends SimplePagerTitleView {
12 | private float mChangePercent = 0.5f;
13 |
14 | public ColorFlipPagerTitleView(Context context) {
15 | super(context);
16 | }
17 |
18 | @Override
19 | public void onLeave(int index, int totalCount, float leavePercent, boolean leftToRight) {
20 | if (leavePercent >= mChangePercent) {
21 | setTextColor(mNormalColor);
22 | } else {
23 | setTextColor(mSelectedColor);
24 | }
25 | }
26 |
27 | @Override
28 | public void onEnter(int index, int totalCount, float enterPercent, boolean leftToRight) {
29 | if (enterPercent >= mChangePercent) {
30 | setTextColor(mSelectedColor);
31 | } else {
32 | setTextColor(mNormalColor);
33 | }
34 | }
35 |
36 | @Override
37 | public void onSelected(int index, int totalCount) {
38 | }
39 |
40 | @Override
41 | public void onDeselected(int index, int totalCount) {
42 | }
43 |
44 | public float getChangePercent() {
45 | return mChangePercent;
46 | }
47 |
48 | public void setChangePercent(float changePercent) {
49 | mChangePercent = changePercent;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "com.siberiadante.multiscrolldemo"
7 | minSdkVersion 17
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | repositories {
22 | maven { url 'https://jitpack.io' }
23 | }
24 | dependencies {
25 | implementation fileTree(dir: 'libs', include: ['*.jar'])
26 | implementation 'com.android.support:appcompat-v7:26.1.0'
27 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
28 | testImplementation 'junit:junit:4.12'
29 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
30 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
31 | compile 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.4-4'
32 | compile 'com.android.support:design:26.1.0'
33 | compile 'com.jakewharton:butterknife:8.7.0'
34 | // compile "com.github.SibreiaDante:SiberiaDanteLib:v1.0.8"
35 | compile 'de.hdodenhof:circleimageview:2.1.0'
36 | compile 'com.jude:easyrecyclerview:4.4.2'
37 | compile 'me.codeboy.android:align-text-view:2.3.1'
38 | compile 'com.github.hackware1993:MagicIndicator:1.5.0'
39 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0'
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/util/DeviceUtil.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.util;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 |
6 | import java.lang.reflect.Method;
7 |
8 | /**
9 | * @Created SiberiaDante
10 | * @Describe:
11 | * @CreateTime: 2018/1/16
12 | * @UpDateTime:
13 | * @Email: 2654828081@qq.com
14 | * @GitHub: https://github.com/SiberiaDante
15 | * @Blogs: http://www.cnblogs.com/shen-hua/
16 | */
17 |
18 | public class DeviceUtil {
19 |
20 | /**
21 | * 是否是华为
22 | */
23 | public static boolean isHUAWEI() {
24 | return android.os.Build.MANUFACTURER.equals("HUAWEI");
25 | }
26 |
27 | //获取是否存在NavigationBar
28 | public static boolean checkDeviceHasNavigationBar(Context context) {
29 | boolean hasNavigationBar = false;
30 | try {
31 | Resources rs = context.getResources();
32 | int id = rs.getIdentifier("config_showNavigationBar", "bool", "android");
33 | if (id > 0) {
34 | hasNavigationBar = rs.getBoolean(id);
35 | }
36 | Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
37 | Method m = systemPropertiesClass.getMethod("get", String.class);
38 | String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
39 | if ("1".equals(navBarOverride)) {
40 | hasNavigationBar = false;
41 | } else if ("0".equals(navBarOverride)) {
42 | hasNavigationBar = true;
43 | }
44 | } catch (Exception e) {
45 |
46 | }
47 | return hasNavigationBar;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/view/NormalDecoration.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.view;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Rect;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.View;
8 |
9 | /**
10 | * @Created: SiberiaDante
11 | * @Date: 2017/11/11
12 | * @Describe:
13 | * @github: https://github.com/SiberiaDante
14 | * @博客园: http://www.cnblogs.com/shen-hua/
15 | */
16 |
17 | public class NormalDecoration extends RecyclerView.ItemDecoration {
18 |
19 | private Paint mPaint;
20 | private int mHeight;
21 |
22 | public NormalDecoration(int color, int height) {
23 | this.mHeight = height;
24 | mPaint = new Paint();
25 | mPaint.setColor(color);
26 | mPaint.setAntiAlias(true);
27 | }
28 |
29 | @Override
30 |
31 | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
32 | super.onDraw(c, parent, state);
33 | int childCount = parent.getChildCount();
34 | Rect rect = new Rect();
35 | rect.left = parent.getPaddingLeft();
36 | rect.right = parent.getWidth() - parent.getPaddingRight();
37 | for (int i = 0; i < childCount; i++) {
38 | View childView = parent.getChildAt(i);
39 | rect.top = childView.getBottom();
40 | rect.bottom = rect.top + mHeight;
41 | c.drawRect(rect, mPaint);
42 | }
43 | }
44 |
45 |
46 | @Override
47 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
48 | super.getItemOffsets(outRect, view, parent, state);
49 | outRect.bottom += mHeight;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/fragment/base/LazyFragment.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.fragment.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.view.View;
6 |
7 |
8 |
9 | /**
10 | * @Created SiberiaDante
11 | * @Describe:
12 | * @CreateTime: 2017/12/5
13 | * @UpDateTime:
14 | * @Email: 2654828081@qq.com
15 | * @GitHub: https://github.com/SiberiaDante
16 | */
17 |
18 | public abstract class LazyFragment extends BaseFragment {
19 | public static final String TAG = LazyFragment.class.getSimpleName();
20 |
21 |
22 | private boolean hasLoaded = false;
23 |
24 | private boolean isCreated = false;
25 |
26 | private boolean isVisibleToUser = false;
27 | private View view;
28 |
29 | @Override
30 | protected void initViews(View view, @Nullable Bundle savedInstanceState) {
31 | isCreated = true;
32 | this.view = view;
33 | lazyLoad(this.view, savedInstanceState);
34 | }
35 |
36 | @Override
37 | public void setUserVisibleHint(boolean isVisibleToUser) {
38 | this.isVisibleToUser = isVisibleToUser;//注:关键步骤
39 | super.setUserVisibleHint(isVisibleToUser);
40 | lazyLoad(view, null);
41 | }
42 |
43 | private void lazyLoad(View view, Bundle savedInstanceState) {
44 | if (!isVisibleToUser || hasLoaded || !isCreated) {
45 | return;
46 | }
47 | lazyInitView(view, savedInstanceState);
48 | hasLoaded = true;//注:关键步骤,确保数据只加载一次
49 | }
50 |
51 | public abstract void lazyInitView(View view, Bundle savedInstanceState);
52 |
53 | @Override
54 | public void onDestroyView() {
55 | super.onDestroyView();
56 | isCreated = false;
57 | hasLoaded = false;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/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_item_publish_article.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
23 |
24 |
32 |
33 |
34 |
48 |
49 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_dynamic_comment.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
21 |
22 |
31 |
32 |
38 |
39 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/fragment/base/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.fragment.base;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v4.app.Fragment;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 |
12 |
13 | import butterknife.ButterKnife;
14 | import butterknife.Unbinder;
15 |
16 | /**
17 | * @Created SiberiaDante
18 | * @Describe:
19 | * @CreateTime: 2017/12/5
20 | * @UpDateTime:
21 | * @Email: 2654828081@qq.com
22 | * @GitHub: https://github.com/SiberiaDante
23 | */
24 |
25 | public abstract class BaseFragment extends Fragment {
26 | public static final String TAG = BaseFragment.class.getSimpleName();
27 |
28 | public Activity mActivity;
29 | public Unbinder unbinder;
30 | private View view;
31 |
32 | @Override
33 | public void onAttach(Context context) {
34 | super.onAttach(context);
35 | mActivity = (Activity) context;
36 | }
37 |
38 | @Nullable
39 | @Override
40 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
41 | if (view == null) {
42 | view = inflater.inflate(getLayoutId(), container, false);
43 | unbinder = ButterKnife.bind(this, view);
44 | initViews(view, savedInstanceState);
45 | initData();
46 | }
47 | return view;
48 | }
49 |
50 | protected abstract int getLayoutId();
51 |
52 | protected abstract void initViews(View view, @Nullable Bundle savedInstanceState);
53 |
54 | protected abstract void initData();
55 |
56 | @Override
57 | public void onDestroyView() {
58 | super.onDestroyView();
59 | unbinder.unbind();
60 | }
61 |
62 |
63 | @Override
64 | public void onDestroy() {
65 | super.onDestroy();
66 | this.view = null;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 11sp
5 | 12sp
6 | 13sp
7 | 14sp
8 | 15sp
9 | 16sp
10 | 17sp
11 | 18sp
12 |
13 |
14 | 21sp
15 | 22sp
16 | 36sp
17 |
18 |
19 |
20 | 0dp
21 | 0.5dp
22 | 1dp
23 | 2dp
24 | 3dp
25 | 4dp
26 | 5dp
27 | 6dp
28 | 7dp
29 | 8dp
30 | 9dp
31 | 10dp
32 | 12dp
33 | 14dp
34 | 15dp
35 | 16dp
36 | 18dp
37 | 19dp
38 | 20dp
39 | 25dp
40 | 32dp
41 | 38dp
42 | 45dp
43 | 48dp
44 | 50dp
45 | 54dp
46 | 63dp
47 | 11dp
48 | 13dp
49 | 42dp
50 | 17dp
51 | 21dp
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/view/JudgeNestedScrollView.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.view;
2 |
3 | import android.content.Context;
4 | import android.support.v4.widget.NestedScrollView;
5 | import android.util.AttributeSet;
6 | import android.util.Log;
7 | import android.view.MotionEvent;
8 | import android.view.ViewConfiguration;
9 |
10 | /**
11 | * @Created SiberiaDante
12 | * @Describe:
13 | * @CreateTime: 2017/12/17
14 | * @UpDateTime:
15 | * @Email: 2654828081@qq.com
16 | * @GitHub: https://github.com/SiberiaDante
17 | */
18 |
19 | public class JudgeNestedScrollView extends NestedScrollView {
20 | private boolean isNeedScroll = true;
21 | private float xDistance, yDistance, xLast, yLast;
22 | private int scaledTouchSlop;
23 |
24 | public JudgeNestedScrollView(Context context) {
25 | super(context, null);
26 | }
27 |
28 | public JudgeNestedScrollView(Context context, AttributeSet attrs) {
29 | super(context, attrs, 0);
30 | }
31 |
32 | public JudgeNestedScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
33 | super(context, attrs, defStyleAttr);
34 | scaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
35 | }
36 |
37 | @Override
38 | public boolean onInterceptTouchEvent(MotionEvent ev) {
39 | switch (ev.getAction()) {
40 | case MotionEvent.ACTION_DOWN:
41 | xDistance = yDistance = 0f;
42 | xLast = ev.getX();
43 | yLast = ev.getY();
44 | break;
45 | case MotionEvent.ACTION_MOVE:
46 | final float curX = ev.getX();
47 | final float curY = ev.getY();
48 |
49 | xDistance += Math.abs(curX - xLast);
50 | yDistance += Math.abs(curY - yLast);
51 | xLast = curX;
52 | yLast = curY;
53 | Log.e("SiberiaDante", "xDistance :" + xDistance + "---yDistance:" + yDistance);
54 | return !(xDistance >= yDistance || yDistance < scaledTouchSlop) && isNeedScroll;
55 |
56 | }
57 | return super.onInterceptTouchEvent(ev);
58 | }
59 |
60 | /*
61 | 该方法用来处理NestedScrollView是否拦截滑动事件
62 | */
63 | public void setNeedScroll(boolean isNeedScroll) {
64 | this.isNeedScroll = isNeedScroll;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_dynamic_follow.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
16 |
17 |
22 |
23 |
28 |
29 |
34 |
35 |
44 |
45 |
50 |
51 |
52 |
53 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/fragment/ArticleFragment.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.content.ContextCompat;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.util.Log;
8 | import android.view.View;
9 | import android.widget.Toast;
10 |
11 | import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
12 | import com.siberiadante.multiscrolldemo.R;
13 | import com.siberiadante.multiscrolldemo.adapter.MineArticleAdapter;
14 | import com.siberiadante.multiscrolldemo.bean.MineArticleBean;
15 | import com.siberiadante.multiscrolldemo.fragment.base.LazyFragment;
16 | import com.siberiadante.multiscrolldemo.view.NormalDecoration;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | import butterknife.BindView;
22 |
23 | /**
24 | * @Created SiberiaDante
25 | * @Describe:
26 | * @CreateTime: 2017/12/14
27 | * @UpDateTime:
28 | * @Email: 2654828081@qq.com
29 | * @GitHub: https://github.com/SiberiaDante
30 | */
31 |
32 | public class ArticleFragment extends LazyFragment {
33 |
34 | @BindView(R.id.recycler_view)
35 | RecyclerView recyclerView;
36 | private MineArticleAdapter adapter;
37 |
38 | public static ArticleFragment getInstance() {
39 | return new ArticleFragment();
40 | }
41 |
42 | @Override
43 | protected int getLayoutId() {
44 | return R.layout.fragment_article;
45 | }
46 |
47 | @Override
48 | protected void initData() {
49 |
50 | }
51 |
52 | @Override
53 | public void lazyInitView(View view, Bundle savedInstanceState) {
54 | final List data = new ArrayList<>();
55 | for (int i = 0; i < 20; i++) {
56 | final MineArticleBean articleBean = new MineArticleBean();
57 | articleBean.setContent("使用NestedScrollView+ViewPager+RecyclerView+SmartRefreshLayout打造酷炫下拉视差效果并解决各种滑动冲突" + i);
58 | data.add(articleBean);
59 | }
60 | recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
61 | recyclerView.addItemDecoration(new NormalDecoration(ContextCompat.getColor(mActivity, R.color.mainGrayF8), (int) mActivity.getResources().getDimension(R.dimen.one)));
62 |
63 | adapter = new MineArticleAdapter(mActivity);
64 | recyclerView.setAdapter(adapter);
65 | adapter.addAll(data);
66 | adapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
67 | @Override
68 | public void onItemClick(int position) {
69 | Toast.makeText(mActivity, "---position---" + position, Toast.LENGTH_SHORT).show();
70 | }
71 | });
72 | adapter.setNoMore(R.layout.view_no_more);
73 | adapter.setMore(R.layout.view_more, new RecyclerArrayAdapter.OnMoreListener() {
74 | @Override
75 | public void onMoreShow() {
76 | Log.d(TAG, "----onMoreShow");
77 | adapter.addAll(data);
78 | }
79 |
80 | @Override
81 | public void onMoreClick() {
82 |
83 | }
84 | });
85 |
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/adapter/MineDynamicAdapter.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.adapter;
2 |
3 |
4 | import android.content.Context;
5 | import android.view.ViewGroup;
6 | import android.widget.TextView;
7 |
8 | import com.jude.easyrecyclerview.adapter.BaseViewHolder;
9 | import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
10 | import com.siberiadante.multiscrolldemo.R;
11 | import com.siberiadante.multiscrolldemo.bean.MineDynamicBean;
12 |
13 | /**
14 | * @Created SiberiaDante
15 | * @Describe:
16 | * @CreateTime: 2017/12/15
17 | * @UpDateTime:
18 | * @Email: 2654828081@qq.com
19 | * @GitHub: https://github.com/SiberiaDante
20 | */
21 |
22 | public class MineDynamicAdapter extends RecyclerArrayAdapter {
23 | public MineDynamicAdapter(Context context) {
24 | super(context);
25 | }
26 |
27 | @Override
28 | public int getViewType(int position) {
29 | final int type = getItem(position).getType();
30 | if (type == 0) {
31 | return 0;
32 | }
33 | if (type == 1) {
34 | return 1;
35 | }
36 | if (type == 2) {
37 | return 2;
38 | }
39 | return -1;
40 | }
41 |
42 | @Override
43 | public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
44 | switch (viewType) {
45 | case 0:
46 | return new DynamicArticleHolder(parent);
47 |
48 | case 1:
49 | return new DynamicCommentHolder(parent);
50 |
51 | case 2:
52 | return new DynamicFollowHolder(parent);
53 | }
54 | return new DynamicArticleHolder(parent);
55 | }
56 |
57 | public class DynamicArticleHolder extends BaseViewHolder {
58 |
59 | TextView textView;
60 |
61 | public DynamicArticleHolder(ViewGroup parent) {
62 | super(parent, R.layout.item_dynamic_article);
63 | textView = $(R.id.tv_title);
64 | }
65 |
66 | @Override
67 | public void setData(MineDynamicBean data) {
68 | super.setData(data);
69 | textView.setText(data.getContent());
70 | }
71 | }
72 |
73 | public class DynamicCommentHolder extends BaseViewHolder {
74 |
75 | TextView textView;
76 |
77 | public DynamicCommentHolder(ViewGroup parent) {
78 | super(parent, R.layout.item_dynamic_comment);
79 | textView = $(R.id.tv_title);
80 | }
81 |
82 | @Override
83 | public void setData(MineDynamicBean data) {
84 | super.setData(data);
85 | textView.setText(data.getContent());
86 | }
87 | }
88 |
89 | public class DynamicFollowHolder extends BaseViewHolder {
90 |
91 | TextView textView;
92 |
93 | public DynamicFollowHolder(ViewGroup parent) {
94 | super(parent, R.layout.item_dynamic_follow);
95 | textView = $(R.id.tv_name);
96 | }
97 |
98 | @Override
99 | public void setData(MineDynamicBean data) {
100 | super.setData(data);
101 | // textView.setText(data.getContent());
102 | }
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/fragment/QuestionFragment.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.content.ContextCompat;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.util.Log;
8 | import android.view.View;
9 | import android.widget.Toast;
10 |
11 | import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
12 | import com.siberiadante.multiscrolldemo.R;
13 | import com.siberiadante.multiscrolldemo.adapter.MineQuestionAdapter;
14 | import com.siberiadante.multiscrolldemo.bean.MineQuestionBean;
15 | import com.siberiadante.multiscrolldemo.fragment.base.LazyFragment;
16 | import com.siberiadante.multiscrolldemo.view.NormalDecoration;
17 |
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | import butterknife.BindView;
23 |
24 | /**
25 | * @Created SiberiaDante
26 | * @Describe:
27 | * @CreateTime: 2017/12/14
28 | * @UpDateTime:
29 | * @Email: 2654828081@qq.com
30 | * @GitHub: https://github.com/SiberiaDante
31 | */
32 |
33 | public class QuestionFragment extends LazyFragment {
34 | public static final String TAG = QuestionFragment.class.getSimpleName();
35 |
36 | @BindView(R.id.recycler_view)
37 | RecyclerView recyclerView;
38 | // @BindView(R.id.refreshLayout)
39 | // SmartRefreshLayout refreshLayout;
40 | private MineQuestionAdapter adapter;
41 |
42 | public static QuestionFragment getInstance() {
43 | return new QuestionFragment();
44 | }
45 |
46 | @Override
47 | protected int getLayoutId() {
48 | return R.layout.fragment_question;
49 | }
50 |
51 | @Override
52 | public void lazyInitView(View view, Bundle savedInstanceState) {
53 |
54 |
55 | final List data = new ArrayList<>();
56 | for (int i = 0; i < 20; i++) {
57 | final MineQuestionBean questionBean = new MineQuestionBean();
58 | questionBean.setContent("使用NestedScrollView+ViewPager+RecyclerView+SmartRefreshLayout打造酷炫下拉视差效果并解决各种滑动冲突" + i);
59 | data.add(questionBean);
60 | }
61 | recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
62 | recyclerView.addItemDecoration(new NormalDecoration(ContextCompat.getColor(mActivity, R.color.mainGrayF8), (int) mActivity.getResources().getDimension(R.dimen.eight)));
63 |
64 | adapter = new MineQuestionAdapter(mActivity);
65 | recyclerView.setAdapter(adapter);
66 | adapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
67 | @Override
68 | public void onItemClick(int position) {
69 | Toast.makeText(mActivity, "---position---" + position, Toast.LENGTH_SHORT).show();
70 | }
71 | });
72 | adapter.addAll(data);
73 | adapter.setNoMore(R.layout.view_no_more);
74 | adapter.setMore(R.layout.view_more, new RecyclerArrayAdapter.OnMoreListener() {
75 | @Override
76 | public void onMoreShow() {
77 | Log.d(TAG, "----onMoreShow");
78 | adapter.addAll(data);
79 | }
80 |
81 | @Override
82 | public void onMoreClick() {
83 |
84 | }
85 | });
86 |
87 | }
88 | @Override
89 | protected void initData() {
90 |
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/fragment/DynamicFragment.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.content.ContextCompat;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.util.Log;
8 | import android.view.View;
9 | import android.widget.Toast;
10 |
11 |
12 | import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
13 | import com.siberiadante.multiscrolldemo.R;
14 | import com.siberiadante.multiscrolldemo.adapter.MineDynamicAdapter;
15 | import com.siberiadante.multiscrolldemo.bean.MineDynamicBean;
16 | import com.siberiadante.multiscrolldemo.fragment.base.LazyFragment;
17 | import com.siberiadante.multiscrolldemo.view.NormalDecoration;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | import butterknife.BindView;
23 |
24 | /**
25 | * @Created SiberiaDante
26 | * @Describe:
27 | * @CreateTime: 2017/12/14
28 | * @UpDateTime:
29 | * @Email: 2654828081@qq.com
30 | * @GitHub: https://github.com/SiberiaDante
31 | */
32 |
33 | public class DynamicFragment extends LazyFragment {
34 |
35 | @BindView(R.id.recycler_view)
36 | RecyclerView recyclerView;
37 |
38 | private MineDynamicAdapter adapter;
39 |
40 | public static DynamicFragment getInstance() {
41 | return new DynamicFragment();
42 | }
43 |
44 | @Override
45 | protected int getLayoutId() {
46 | return R.layout.fragment_dynamic;
47 | }
48 |
49 | @Override
50 | protected void initData() {
51 |
52 | }
53 |
54 | @Override
55 | public void lazyInitView(View view, Bundle savedInstanceState) {
56 | final List data = new ArrayList<>();
57 | for (int i = 0; i < 20; i++) {
58 | final MineDynamicBean questionBean = new MineDynamicBean();
59 | questionBean.setContent("使用NestedScrollView+ViewPager+RecyclerView+SmartRefreshLayout打造酷炫下拉视差效果并解决各种滑动冲突" + i);
60 | if (i == 0) {
61 | questionBean.setType(0);
62 | } else {
63 | if (i % 2 == 0) {
64 | questionBean.setType(1);
65 | }
66 | if (i % 3 == 0) {
67 | questionBean.setType(2);
68 | }
69 | }
70 | data.add(questionBean);
71 | }
72 |
73 | recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
74 | recyclerView.addItemDecoration(new NormalDecoration(ContextCompat.getColor(mActivity, R.color.mainGrayF8), (int) mActivity.getResources().getDimension(R.dimen.one)));
75 |
76 | adapter = new MineDynamicAdapter(mActivity);
77 | recyclerView.setAdapter(adapter);
78 | adapter.addAll(data);
79 | adapter.setNoMore(R.layout.view_no_more);
80 | adapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
81 | @Override
82 | public void onItemClick(int position) {
83 | Toast.makeText(mActivity, "---position---" + position, Toast.LENGTH_SHORT).show();
84 | }
85 | });
86 | adapter.setMore(R.layout.view_more, new RecyclerArrayAdapter.OnMoreListener() {
87 | @Override
88 | public void onMoreShow() {
89 | Log.d(TAG, "----onMoreShow");
90 | adapter.addAll(data);
91 | }
92 |
93 | @Override
94 | public void onMoreClick() {
95 |
96 | }
97 | });
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
17 |
18 |
31 |
44 |
45 |
59 |
60 |
61 |
66 |
71 |
72 |
77 |
78 |
86 |
87 |
95 |
96 |
108 |
109 |
114 |
128 |
129 |
135 |
136 |
146 |
147 |
156 |
165 |
166 |
173 |
174 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/util/StatusBarUtil.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.util;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.res.Resources;
6 | import android.os.Build;
7 | import android.support.annotation.FloatRange;
8 | import android.support.annotation.RequiresApi;
9 | import android.util.Log;
10 | import android.util.TypedValue;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.view.Window;
14 | import android.view.WindowManager;
15 |
16 | import java.lang.reflect.Field;
17 | import java.lang.reflect.Method;
18 | import java.util.regex.Pattern;
19 |
20 | /**
21 | * 状态栏透明
22 | * Created by SCWANG on 2016/10/26.
23 | */
24 |
25 | @SuppressWarnings("unused")
26 | public class StatusBarUtil {
27 |
28 | public static int DEFAULT_COLOR = 0;
29 | public static float DEFAULT_ALPHA = 0;//Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? 0.2f : 0.3f;
30 | public static final int MIN_API = 19;
31 |
32 | //
33 | public static void immersive(Activity activity) {
34 | immersive(activity, DEFAULT_COLOR, DEFAULT_ALPHA);
35 | }
36 |
37 | public static void immersive(Activity activity, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) {
38 | immersive(activity.getWindow(), color, alpha);
39 | }
40 |
41 | public static void immersive(Activity activity, int color) {
42 | immersive(activity.getWindow(), color, 1f);
43 | }
44 |
45 | public static void immersive(Window window) {
46 | immersive(window, DEFAULT_COLOR, DEFAULT_ALPHA);
47 | }
48 |
49 | public static void immersive(Window window, int color) {
50 | immersive(window, color, 1f);
51 | }
52 |
53 | public static void immersive(Window window, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) {
54 | if (Build.VERSION.SDK_INT >= 21) {
55 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
56 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
57 | window.setStatusBarColor(mixtureColor(color, alpha));
58 |
59 | int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
60 | systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
61 | systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
62 | window.getDecorView().setSystemUiVisibility(systemUiVisibility);
63 | } else if (Build.VERSION.SDK_INT >= 19) {
64 | window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
65 | setTranslucentView((ViewGroup) window.getDecorView(), color, alpha);
66 | } else if (Build.VERSION.SDK_INT >= MIN_API && Build.VERSION.SDK_INT > 16) {
67 | int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
68 | systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
69 | systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
70 | window.getDecorView().setSystemUiVisibility(systemUiVisibility);
71 | }
72 | }
73 | //
74 |
75 | //
76 | public static void darkMode(Activity activity, boolean dark) {
77 | if (isFlyme4Later()) {
78 | darkModeForFlyme4(activity.getWindow(), dark);
79 | } else if (isMIUI6Later()) {
80 | darkModeForMIUI6(activity.getWindow(), dark);
81 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
82 | darkModeForM(activity.getWindow(), dark);
83 | }
84 | }
85 |
86 | /** 设置状态栏darkMode,字体颜色及icon变黑(目前支持MIUI6以上,Flyme4以上,Android M以上) */
87 | public static void darkMode(Activity activity) {
88 | darkMode(activity.getWindow(), DEFAULT_COLOR, DEFAULT_ALPHA);
89 | }
90 |
91 | public static void darkMode(Activity activity, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) {
92 | darkMode(activity.getWindow(), color, alpha);
93 | }
94 |
95 | /** 设置状态栏darkMode,字体颜色及icon变黑(目前支持MIUI6以上,Flyme4以上,Android M以上) */
96 | public static void darkMode(Window window, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) {
97 | if (isFlyme4Later()) {
98 | darkModeForFlyme4(window, true);
99 | immersive(window,color,alpha);
100 | } else if (isMIUI6Later()) {
101 | darkModeForMIUI6(window, true);
102 | immersive(window,color,alpha);
103 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
104 | darkModeForM(window, true);
105 | immersive(window, color, alpha);
106 | } else if (Build.VERSION.SDK_INT >= 19) {
107 | window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
108 | setTranslucentView((ViewGroup) window.getDecorView(), color, alpha);
109 | } else {
110 | immersive(window, color, alpha);
111 | }
112 | // if (Build.VERSION.SDK_INT >= 21) {
113 | // window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
114 | // window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
115 | // window.setStatusBarColor(Color.TRANSPARENT);
116 | // } else if (Build.VERSION.SDK_INT >= 19) {
117 | // window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
118 | // }
119 |
120 | // setTranslucentView((ViewGroup) window.getDecorView(), color, alpha);
121 | }
122 |
123 | //------------------------->
124 |
125 | /** android 6.0设置字体颜色 */
126 | @RequiresApi(Build.VERSION_CODES.M)
127 | private static void darkModeForM(Window window, boolean dark) {
128 | // window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
129 | // window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
130 | // window.setStatusBarColor(Color.TRANSPARENT);
131 |
132 | int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
133 | if (dark) {
134 | systemUiVisibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
135 | } else {
136 | systemUiVisibility &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
137 | }
138 | window.getDecorView().setSystemUiVisibility(systemUiVisibility);
139 | }
140 |
141 | /**
142 | * 设置Flyme4+的darkMode,darkMode时候字体颜色及icon变黑
143 | * http://open-wiki.flyme.cn/index.php?title=Flyme%E7%B3%BB%E7%BB%9FAPI
144 | */
145 | public static boolean darkModeForFlyme4(Window window, boolean dark) {
146 | boolean result = false;
147 | if (window != null) {
148 | try {
149 | WindowManager.LayoutParams e = window.getAttributes();
150 | Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
151 | Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags");
152 | darkFlag.setAccessible(true);
153 | meizuFlags.setAccessible(true);
154 | int bit = darkFlag.getInt(null);
155 | int value = meizuFlags.getInt(e);
156 | if (dark) {
157 | value |= bit;
158 | } else {
159 | value &= ~bit;
160 | }
161 |
162 | meizuFlags.setInt(e, value);
163 | window.setAttributes(e);
164 | result = true;
165 | } catch (Exception var8) {
166 | Log.e("StatusBar", "darkIcon: failed");
167 | }
168 | }
169 |
170 | return result;
171 | }
172 |
173 | /**
174 | * 设置MIUI6+的状态栏是否为darkMode,darkMode时候字体颜色及icon变黑
175 | * http://dev.xiaomi.com/doc/p=4769/
176 | */
177 | public static boolean darkModeForMIUI6(Window window, boolean darkmode) {
178 | Class extends Window> clazz = window.getClass();
179 | try {
180 | int darkModeFlag = 0;
181 | Class> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
182 | Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
183 | darkModeFlag = field.getInt(layoutParams);
184 | Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
185 | extraFlagField.invoke(window, darkmode ? darkModeFlag : 0, darkModeFlag);
186 | return true;
187 | } catch (Exception e) {
188 | e.printStackTrace();
189 | return false;
190 | }
191 | }
192 |
193 | /** 判断是否Flyme4以上 */
194 | public static boolean isFlyme4Later() {
195 | return Build.FINGERPRINT.contains("Flyme_OS_4")
196 | || Build.VERSION.INCREMENTAL.contains("Flyme_OS_4")
197 | || Pattern.compile("Flyme OS [4|5]", Pattern.CASE_INSENSITIVE).matcher(Build.DISPLAY).find();
198 | }
199 |
200 | /** 判断是否为MIUI6以上 */
201 | public static boolean isMIUI6Later() {
202 | try {
203 | Class> clz = Class.forName("android.os.SystemProperties");
204 | Method mtd = clz.getMethod("get", String.class);
205 | String val = (String) mtd.invoke(null, "ro.miui.ui.version.name");
206 | val = val.replaceAll("[vV]", "");
207 | int version = Integer.parseInt(val);
208 | return version >= 6;
209 | } catch (Exception e) {
210 | return false;
211 | }
212 | }
213 | //
214 |
215 |
216 | /** 增加View的paddingTop,增加的值为状态栏高度 */
217 | public static void setPadding(Context context, View view) {
218 | if (Build.VERSION.SDK_INT >= MIN_API) {
219 | view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + getStatusBarHeight(context),
220 | view.getPaddingRight(), view.getPaddingBottom());
221 | }
222 | }
223 | /** 增加View的paddingTop,增加的值为状态栏高度 (智能判断,并设置高度)*/
224 | public static void setPaddingSmart(Context context, View view) {
225 | if (Build.VERSION.SDK_INT >= MIN_API) {
226 | ViewGroup.LayoutParams lp = view.getLayoutParams();
227 | if (lp != null && lp.height > 0) {
228 | lp.height += getStatusBarHeight(context);//增高
229 | }
230 | view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + getStatusBarHeight(context),
231 | view.getPaddingRight(), view.getPaddingBottom());
232 | }
233 | }
234 |
235 | /** 增加View的高度以及paddingTop,增加的值为状态栏高度.一般是在沉浸式全屏给ToolBar用的 */
236 | public static void setHeightAndPadding(Context context, View view) {
237 | if (Build.VERSION.SDK_INT >= MIN_API) {
238 | ViewGroup.LayoutParams lp = view.getLayoutParams();
239 | lp.height += getStatusBarHeight(context);//增高
240 | view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + getStatusBarHeight(context),
241 | view.getPaddingRight(), view.getPaddingBottom());
242 | }
243 | }
244 | /** 增加View上边距(MarginTop)一般是给高度为 WARP_CONTENT 的小控件用的*/
245 | public static void setMargin(Context context, View view) {
246 | if (Build.VERSION.SDK_INT >= MIN_API) {
247 | ViewGroup.LayoutParams lp = view.getLayoutParams();
248 | if (lp instanceof ViewGroup.MarginLayoutParams) {
249 | ((ViewGroup.MarginLayoutParams) lp).topMargin += getStatusBarHeight(context);//增高
250 | }
251 | view.setLayoutParams(lp);
252 | }
253 | }
254 | /**
255 | * 创建假的透明栏
256 | */
257 | public static void setTranslucentView(ViewGroup container, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) {
258 | if (Build.VERSION.SDK_INT >= 19) {
259 | int mixtureColor = mixtureColor(color, alpha);
260 | View translucentView = container.findViewById(android.R.id.custom);
261 | if (translucentView == null && mixtureColor != 0) {
262 | translucentView = new View(container.getContext());
263 | translucentView.setId(android.R.id.custom);
264 | ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(
265 | ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(container.getContext()));
266 | container.addView(translucentView, lp);
267 | }
268 | if (translucentView != null) {
269 | translucentView.setBackgroundColor(mixtureColor);
270 | }
271 | }
272 | }
273 |
274 | public static int mixtureColor(int color, @FloatRange(from = 0.0, to = 1.0) float alpha) {
275 | int a = (color & 0xff000000) == 0 ? 0xff : color >>> 24;
276 | return (color & 0x00ffffff) | (((int) (a * alpha)) << 24);
277 | }
278 |
279 | /** 获取状态栏高度 */
280 | public static int getStatusBarHeight(Context context) {
281 | int result = 24;
282 | int resId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
283 | if (resId > 0) {
284 | result = context.getResources().getDimensionPixelSize(resId);
285 | } else {
286 | result = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
287 | result, Resources.getSystem().getDisplayMetrics());
288 | }
289 | return result;
290 | }
291 | }
292 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/multiscrolldemo/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.multiscrolldemo.activity;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.content.ContextCompat;
7 | import android.support.v4.view.ViewPager;
8 | import android.support.v4.widget.NestedScrollView;
9 | import android.support.v7.widget.ButtonBarLayout;
10 | import android.support.v7.widget.Toolbar;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.view.animation.AccelerateInterpolator;
14 | import android.view.animation.DecelerateInterpolator;
15 | import android.widget.ImageView;
16 | import android.widget.Toast;
17 |
18 | import com.scwang.smartrefresh.layout.SmartRefreshLayout;
19 | import com.scwang.smartrefresh.layout.api.RefreshHeader;
20 | import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener;
21 | import com.scwang.smartrefresh.layout.util.DensityUtil;
22 | import com.siberiadante.multiscrolldemo.R;
23 | import com.siberiadante.multiscrolldemo.adapter.ComFragmentAdapter;
24 | import com.siberiadante.multiscrolldemo.fragment.ArticleFragment;
25 | import com.siberiadante.multiscrolldemo.fragment.DynamicFragment;
26 | import com.siberiadante.multiscrolldemo.fragment.QuestionFragment;
27 | import com.siberiadante.multiscrolldemo.util.ScreenUtil;
28 | import com.siberiadante.multiscrolldemo.util.StatusBarUtil;
29 | import com.siberiadante.multiscrolldemo.view.ColorFlipPagerTitleView;
30 | import com.siberiadante.multiscrolldemo.view.JudgeNestedScrollView;
31 |
32 | import net.lucode.hackware.magicindicator.MagicIndicator;
33 | import net.lucode.hackware.magicindicator.ViewPagerHelper;
34 | import net.lucode.hackware.magicindicator.buildins.UIUtil;
35 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;
36 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
37 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
38 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
39 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
40 | import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;
41 |
42 | import java.util.ArrayList;
43 | import java.util.Arrays;
44 | import java.util.List;
45 |
46 | import butterknife.BindView;
47 | import butterknife.OnClick;
48 |
49 | public class MainActivity extends BaseActivity {
50 | public static final String TAG = MainActivity.class.getSimpleName();
51 |
52 | @BindView(R.id.iv_back)
53 | ImageView ivBack;
54 | @BindView(R.id.iv_menu)
55 | ImageView ivMenu;
56 |
57 | @BindView(R.id.iv_header)
58 | ImageView ivHeader;
59 | @BindView(R.id.refreshLayout)
60 | SmartRefreshLayout refreshLayout;
61 | @BindView(R.id.toolbar)
62 | Toolbar toolbar;
63 | @BindView(R.id.view_pager)
64 | ViewPager viewPager;
65 | @BindView(R.id.scrollView)
66 | JudgeNestedScrollView scrollView;
67 | @BindView(R.id.buttonBarLayout)
68 | ButtonBarLayout buttonBarLayout;
69 | @BindView(R.id.magic_indicator)
70 | MagicIndicator magicIndicator;
71 | @BindView(R.id.magic_indicator_title)
72 | MagicIndicator magicIndicatorTitle;
73 | int toolBarPositionY = 0;
74 | private int mOffset = 0;
75 | private int mScrollY = 0;
76 | private String[] mTitles = new String[]{"动态", "文章", "问答"};
77 | private List mDataList = Arrays.asList(mTitles);
78 | // private ContentObserver mNavigationStatusObserver = new ContentObserver(new Handler()) {
79 | // @Override
80 | // public void onChange(boolean selfChange) {
81 | // dealWithHuaWei();
82 | // int navigationBarIsMin = Settings.System.getInt(getContentResolver(), "navigationbar_is_min", 0);
83 | // if (navigationBarIsMin == 1) {
84 | // Log.d(TAG, "onChange: ------------------导航键隐藏了");
85 | // } else {
86 | // Log.d(TAG, "onChange: ------------------导航键显示了");
87 | // }
88 | // }
89 | // };
90 |
91 | @Override
92 | public int setLayoutId() {
93 | return R.layout.activity_main;
94 | }
95 |
96 | @Override
97 | public void initView(Bundle savedInstanceState) {
98 | initView();
99 | }
100 |
101 | @Override
102 | public void initData() {
103 |
104 | }
105 |
106 | private void initView() {
107 | StatusBarUtil.immersive(this);
108 | StatusBarUtil.setPaddingSmart(this, toolbar);
109 | refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {
110 | @Override
111 | public void onHeaderPulling(RefreshHeader header, float percent, int offset, int bottomHeight, int extendHeight) {
112 | mOffset = offset / 2;
113 | ivHeader.setTranslationY(mOffset - mScrollY);
114 | toolbar.setAlpha(1 - Math.min(percent, 1));
115 | }
116 |
117 | @Override
118 | public void onHeaderReleasing(RefreshHeader header, float percent, int offset, int bottomHeight, int extendHeight) {
119 | mOffset = offset / 2;
120 | ivHeader.setTranslationY(mOffset - mScrollY);
121 | toolbar.setAlpha(1 - Math.min(percent, 1));
122 | }
123 | });
124 |
125 | //判断是否是华为手机并且是否有虚拟导航键
126 | // if (DeviceUtil.isHUAWEI() && DeviceUtil.checkDeviceHasNavigationBar(this.getApplicationContext())) {
127 | // getContentResolver().registerContentObserver(Settings.System.getUriFor
128 | // ("navigationbar_is_min"), true, mNavigationStatusObserver);
129 | // }
130 | toolbar.post(new Runnable() {
131 | @Override
132 | public void run() {
133 | dealWithViewPager();
134 | }
135 | });
136 | scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
137 | int lastScrollY = 0;
138 | int h = DensityUtil.dp2px(170);
139 | int color = ContextCompat.getColor(getApplicationContext(), R.color.mainWhite) & 0x00ffffff;
140 |
141 | @Override
142 | public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
143 | int[] location = new int[2];
144 | magicIndicator.getLocationOnScreen(location);
145 | int yPosition = location[1];
146 | if (yPosition < toolBarPositionY) {
147 | magicIndicatorTitle.setVisibility(View.VISIBLE);
148 | scrollView.setNeedScroll(false);
149 | } else {
150 | magicIndicatorTitle.setVisibility(View.GONE);
151 | scrollView.setNeedScroll(true);
152 |
153 | }
154 |
155 | if (lastScrollY < h) {
156 | scrollY = Math.min(h, scrollY);
157 | mScrollY = scrollY > h ? h : scrollY;
158 | buttonBarLayout.setAlpha(1f * mScrollY / h);
159 | toolbar.setBackgroundColor(((255 * mScrollY / h) << 24) | color);
160 | ivHeader.setTranslationY(mOffset - mScrollY);
161 | }
162 | if (scrollY == 0) {
163 | ivBack.setImageResource(R.drawable.back_white);
164 | ivMenu.setImageResource(R.drawable.icon_menu_white);
165 | } else {
166 | ivBack.setImageResource(R.drawable.back_black);
167 | ivMenu.setImageResource(R.drawable.icon_menu_black);
168 | }
169 |
170 | lastScrollY = scrollY;
171 | }
172 | });
173 | buttonBarLayout.setAlpha(0);
174 | toolbar.setBackgroundColor(0);
175 |
176 |
177 | viewPager.setAdapter(new ComFragmentAdapter(getSupportFragmentManager(), getFragments()));
178 | viewPager.setOffscreenPageLimit(10);
179 | initMagicIndicator();
180 | initMagicIndicatorTitle();
181 | }
182 |
183 | private void dealWithViewPager() {
184 | toolBarPositionY = toolbar.getHeight();
185 | ViewGroup.LayoutParams params = viewPager.getLayoutParams();
186 | params.height = ScreenUtil.getScreenHeightPx(getApplicationContext()) - toolBarPositionY - magicIndicator.getHeight() + 1;
187 | viewPager.setLayoutParams(params);
188 | }
189 |
190 | private List getFragments() {
191 | List fragments = new ArrayList<>();
192 | fragments.add(DynamicFragment.getInstance());
193 | fragments.add(ArticleFragment.getInstance());
194 | fragments.add(QuestionFragment.getInstance());
195 | return fragments;
196 | }
197 |
198 | private void initMagicIndicator() {
199 | CommonNavigator commonNavigator = new CommonNavigator(this);
200 | commonNavigator.setScrollPivotX(0.65f);
201 | commonNavigator.setAdjustMode(true);
202 | commonNavigator.setAdapter(new CommonNavigatorAdapter() {
203 | @Override
204 | public int getCount() {
205 | return mDataList == null ? 0 : mDataList.size();
206 | }
207 |
208 | @Override
209 | public IPagerTitleView getTitleView(Context context, final int index) {
210 | SimplePagerTitleView simplePagerTitleView = new ColorFlipPagerTitleView(context);
211 | simplePagerTitleView.setText(mDataList.get(index));
212 | simplePagerTitleView.setNormalColor(ContextCompat.getColor(MainActivity.this, R.color.mainBlack));
213 | simplePagerTitleView.setSelectedColor(ContextCompat.getColor(MainActivity.this, R.color.mainBlack));
214 | simplePagerTitleView.setTextSize(16);
215 | simplePagerTitleView.setOnClickListener(new View.OnClickListener() {
216 | @Override
217 | public void onClick(View v) {
218 | viewPager.setCurrentItem(index, false);
219 | }
220 | });
221 | return simplePagerTitleView;
222 | }
223 |
224 | @Override
225 | public IPagerIndicator getIndicator(Context context) {
226 | LinePagerIndicator indicator = new LinePagerIndicator(context);
227 | indicator.setMode(LinePagerIndicator.MODE_EXACTLY);
228 | indicator.setLineHeight(UIUtil.dip2px(context, 2));
229 | indicator.setLineWidth(UIUtil.dip2px(context, 20));
230 | indicator.setRoundRadius(UIUtil.dip2px(context, 3));
231 | indicator.setStartInterpolator(new AccelerateInterpolator());
232 | indicator.setEndInterpolator(new DecelerateInterpolator(2.0f));
233 | indicator.setColors(ContextCompat.getColor(MainActivity.this, R.color.mainRed));
234 | return indicator;
235 | }
236 | });
237 | magicIndicator.setNavigator(commonNavigator);
238 | ViewPagerHelper.bind(magicIndicator, viewPager);
239 | }
240 |
241 | private void initMagicIndicatorTitle() {
242 | CommonNavigator commonNavigator = new CommonNavigator(this);
243 | commonNavigator.setScrollPivotX(0.65f);
244 | commonNavigator.setAdjustMode(true);
245 | commonNavigator.setAdapter(new CommonNavigatorAdapter() {
246 | @Override
247 | public int getCount() {
248 | return mDataList == null ? 0 : mDataList.size();
249 | }
250 |
251 | @Override
252 | public IPagerTitleView getTitleView(Context context, final int index) {
253 | SimplePagerTitleView simplePagerTitleView = new ColorFlipPagerTitleView(context);
254 | simplePagerTitleView.setText(mDataList.get(index));
255 | simplePagerTitleView.setNormalColor(ContextCompat.getColor(MainActivity.this, R.color.mainBlack));
256 | simplePagerTitleView.setSelectedColor(ContextCompat.getColor(MainActivity.this, R.color.mainBlack));
257 | simplePagerTitleView.setTextSize(16);
258 | simplePagerTitleView.setOnClickListener(new View.OnClickListener() {
259 | @Override
260 | public void onClick(View v) {
261 | viewPager.setCurrentItem(index, false);
262 | }
263 | });
264 | return simplePagerTitleView;
265 | }
266 |
267 | @Override
268 | public IPagerIndicator getIndicator(Context context) {
269 | LinePagerIndicator indicator = new LinePagerIndicator(context);
270 | indicator.setMode(LinePagerIndicator.MODE_EXACTLY);
271 | indicator.setLineHeight(UIUtil.dip2px(context, 2));
272 | indicator.setLineWidth(UIUtil.dip2px(context, 20));
273 | indicator.setRoundRadius(UIUtil.dip2px(context, 3));
274 | indicator.setStartInterpolator(new AccelerateInterpolator());
275 | indicator.setEndInterpolator(new DecelerateInterpolator(2.0f));
276 | indicator.setColors(ContextCompat.getColor(MainActivity.this, R.color.mainRed));
277 | return indicator;
278 | }
279 | });
280 | magicIndicatorTitle.setNavigator(commonNavigator);
281 | ViewPagerHelper.bind(magicIndicatorTitle, viewPager);
282 |
283 | }
284 |
285 | /**
286 | * 处理华为虚拟键显示隐藏问题导致屏幕高度变化,ViewPager的高度也需要重新测量
287 | */
288 | // private void dealWithHuaWei() {
289 | // flActivity.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
290 | // @Override
291 | // public void onGlobalLayout() {
292 | // dealWithViewPager();
293 | // flActivity.getViewTreeObserver().removeOnGlobalLayoutListener(this);
294 | // }
295 | // });
296 | // }
297 | @OnClick({R.id.tv_username, R.id.iv_avatar, R.id.tv_authentication, R.id.tv_edit_info, R.id.tv_position})
298 | public void onViewClicked(View view) {
299 | switch (view.getId()) {
300 | case R.id.tv_username:
301 | toast("SiberiaDante");
302 | break;
303 | case R.id.iv_avatar:
304 | toast("头像");
305 | break;
306 | case R.id.tv_authentication:
307 | toast("头衔认证");
308 | break;
309 | case R.id.tv_edit_info:
310 | toast("编辑资料");
311 | break;
312 | case R.id.tv_position:
313 | toast("中国·GitHub");
314 | break;
315 | }
316 | }
317 |
318 | private void toast(String msg) {
319 | Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
320 | }
321 | }
322 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
20 |
21 |
26 |
27 |
31 |
32 |
33 |
34 |
40 |
41 |
45 |
46 |
50 |
51 |
58 |
59 |
66 |
67 |
70 |
71 |
76 |
77 |
81 |
82 |
87 |
88 |
89 |
98 |
99 |
100 |
105 |
106 |
116 |
117 |
123 |
124 |
128 |
129 |
135 |
136 |
140 |
141 |
142 |
151 |
152 |
160 |
161 |
167 |
168 |
172 |
173 |
180 |
181 |
182 |
183 |
184 |
190 |
191 |
200 |
201 |
208 |
209 |
218 |
219 |
226 |
227 |
228 |
229 |
235 |
236 |
248 |
249 |
256 |
257 |
263 |
264 |
275 |
276 |
277 |
283 |
284 |
295 |
296 |
297 |
298 |
306 |
307 |
312 |
313 |
317 |
318 |
322 |
323 |
324 |
330 |
331 |
335 |
336 |
340 |
341 |
342 |
343 |
351 |
352 |
357 |
358 |
362 |
363 |
367 |
368 |
369 |
375 |
376 |
380 |
381 |
385 |
386 |
387 |
388 |
397 |
398 |
404 |
405 |
411 |
412 |
416 |
417 |
421 |
422 |
426 |
427 |
428 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
452 |
453 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
467 |
468 |
474 |
475 |
480 |
481 |
486 |
487 |
488 |
495 |
496 |
500 |
501 |
510 |
511 |
512 |
513 |
514 |
520 |
521 |
522 |
523 |
524 |
532 |
533 |
534 |
535 |
--------------------------------------------------------------------------------