├── .gitignore
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── donkingliang
│ │ └── consecutivescrollerdemo
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── donkingliang
│ │ │ └── consecutivescrollerdemo
│ │ │ ├── ConsecutiveActivity.java
│ │ │ ├── FragmentActivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── MyFragment.java
│ │ │ ├── PermanentStickyActivity.java
│ │ │ ├── SampleActivity.java
│ │ │ ├── ScrollChildActivity.java
│ │ │ ├── SinkStickyActivity.java
│ │ │ ├── StickyActivity.java
│ │ │ ├── ViewPager2Activity.java
│ │ │ ├── ViewPagerActivity.java
│ │ │ ├── adapter
│ │ │ ├── MyFragmentPagerAdapter.java
│ │ │ ├── RecyclerViewAdapter.java
│ │ │ └── TabPagerAdapter.java
│ │ │ └── view
│ │ │ └── MyFrameLayout.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable-xhdpi
│ │ └── temp.jpg
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_consecutive.xml
│ │ ├── activity_fragment.xml
│ │ ├── activity_main.xml
│ │ ├── activity_sample.xml
│ │ ├── activity_scroll_child.xml
│ │ ├── activity_sink_sticky.xml
│ │ ├── activity_sticky.xml
│ │ ├── activity_sticky_permanent.xml
│ │ ├── activity_viewpager.xml
│ │ ├── activity_viewpager2.xml
│ │ ├── adapter_recycler_item.xml
│ │ └── fragment_my.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── 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
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── donkingliang
│ └── consecutivescrollerdemo
│ └── ExampleUnitTest.java
├── build.gradle
├── consecutivescroller
├── .gitignore
├── build.gradle
├── consumer-rules.pro
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── donkingliang
│ │ └── consecutivescroller
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── donkingliang
│ │ │ └── consecutivescroller
│ │ │ ├── ConsecutiveScrollerLayout.java
│ │ │ ├── ConsecutiveViewPager.java
│ │ │ ├── ConsecutiveViewPager2.java
│ │ │ ├── IConsecutiveScroller.java
│ │ │ ├── LayoutParamsUtils.java
│ │ │ ├── OverScrollInterpolator.java
│ │ │ ├── ScrollUtils.java
│ │ │ └── Util.java
│ └── res
│ │ └── values
│ │ └── attrs.xml
│ └── test
│ └── java
│ └── com
│ └── donkingliang
│ └── consecutivescroller
│ └── ExampleUnitTest.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── image
├── permanent_sticky.gif
├── sample.gif
├── sink_sticky.gif
├── sticky.gif
└── viewpager.gif
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | /captures
3 |
4 | # Built application files
5 | *.apk
6 | *.ap_
7 |
8 |
9 |
10 | # Generated files
11 | bin/
12 | gen/
13 |
14 | # Gradle files
15 | .gradle/
16 | /build
17 | /*/build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Log Files
26 | *.log
27 |
28 | # Eclipse project files
29 | .classpath
30 | .project
31 | .settings/
32 |
33 | # Intellij project files
34 | *.iml
35 | *.ipr
36 | *.iws
37 | .idea/
38 |
39 | # System files
40 | .DS_Store
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## 简介
2 |
3 | ConsecutiveScrollerLayout是Android下支持多个滑动布局(RecyclerView、ViewPager、WebView、ScrollView等)和普通控件(TextView、ImageView、LinearLayou、自定义View等)持续连贯滑动的容器,它使所有的子View像一个整体一样连续顺畅滑动。
4 |
5 | ConsecutiveScrollerLayout支持多种模式的布局吸顶功能,能动态控制吸顶View的显示位置和状态,能适用于大部分的业务场景。
6 |
7 | ConsecutiveScrollerLayout能通过实现接口,支持复杂的、多层嵌套下的滑动布局的滑动处理。
8 |
9 | ConsecutiveScrollerLayout支持NestedScrolling机制。
10 |
11 | ## 效果图
12 |
13 | 
14 | 
15 | 
16 | 
17 | 
18 |
19 | ## 引入依赖
20 |
21 | 在Project的build.gradle在添加以下代码
22 |
23 | ```groovy
24 | allprojects {
25 | repositories {
26 | ...
27 | maven { url 'https://jitpack.io' }
28 | }
29 | }
30 | ```
31 | 在Module的build.gradle在添加以下代码
32 | ```groovy
33 |
34 | implementation 'com.github.donkingliang:ConsecutiveScroller:4.6.4'
35 | ```
36 |
37 | ## 使用文档
38 |
39 | 查看文档请移步 [wiki](https://github.com/donkingliang/ConsecutiveScroller/wiki)
40 |
41 | ## LICENSE
42 |
43 |
44 |
45 | ConsecutiveScroller 基于 Apache-2.0 协议进行分发和使用,更多信息参见 [协议文件](LICENSE)。
46 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 30
5 | defaultConfig {
6 | applicationId "com.donkingliang.consecutivescroller"
7 | minSdkVersion 19
8 | targetSdkVersion 30
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'androidx.appcompat:appcompat:1.3.1'
24 | implementation 'com.google.android.material:material:1.4.0'
25 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
26 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
27 | testImplementation 'junit:junit:4.13.2'
28 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
29 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
30 | implementation 'androidx.recyclerview:recyclerview:1.2.1'
31 | implementation project(':consecutivescroller')
32 |
33 | // 刷新框架
34 | implementation 'com.scwang.smart:refresh-layout-kernel:2.0.3' //核心必须依赖
35 | implementation 'com.scwang.smart:refresh-header-classics:2.0.3' //经典刷新头
36 | implementation 'com.scwang.smart:refresh-footer-classics:2.0.3' //经典加载
37 |
38 | implementation 'androidx.viewpager2:viewpager2:1.1.0-alpha01'
39 | }
40 |
--------------------------------------------------------------------------------
/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/androidTest/java/com/donkingliang/consecutivescrollerdemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescrollerdemo;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 |
25 | assertEquals("com.donkingliang.consecutivescroller", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/donkingliang/consecutivescrollerdemo/ConsecutiveActivity.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescrollerdemo;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 | import androidx.recyclerview.widget.LinearLayoutManager;
5 | import androidx.recyclerview.widget.RecyclerView;
6 |
7 | import android.os.Bundle;
8 |
9 | import com.donkingliang.consecutivescrollerdemo.adapter.RecyclerViewAdapter;
10 |
11 | public class ConsecutiveActivity extends AppCompatActivity {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_consecutive);
17 |
18 | RecyclerView recyclerView1 = findViewById(R.id.recyclerView1);
19 | recyclerView1.setLayoutManager(new LinearLayoutManager(this));
20 | RecyclerViewAdapter adapter1 = new RecyclerViewAdapter(this,"RecyclerView1-");
21 | recyclerView1.setAdapter(adapter1);
22 |
23 | RecyclerView recyclerView2 = findViewById(R.id.recyclerView2);
24 | recyclerView2.setLayoutManager(new LinearLayoutManager(this));
25 | RecyclerViewAdapter adapter2 = new RecyclerViewAdapter(this,"RecyclerView2-");
26 | recyclerView2.setAdapter(adapter2);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/donkingliang/consecutivescrollerdemo/FragmentActivity.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescrollerdemo;
2 |
3 | import android.os.Bundle;
4 |
5 | import androidx.appcompat.app.AppCompatActivity;
6 | import androidx.fragment.app.FragmentManager;
7 | import androidx.fragment.app.FragmentTransaction;
8 |
9 | /**
10 | * @Author teach liang
11 | * @Description
12 | * @Date 2020/5/22
13 | */
14 | public class FragmentActivity extends AppCompatActivity {
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_fragment);
20 |
21 | FragmentManager fragmentManager = getSupportFragmentManager();
22 | FragmentTransaction transaction = fragmentManager.beginTransaction(); // 开启一个事务
23 | transaction.replace(R.id.fragment_container, new MyFragment());
24 | transaction.commit();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/donkingliang/consecutivescrollerdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescrollerdemo;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.content.Intent;
6 | import android.os.Bundle;
7 | import android.view.View;
8 |
9 | public class MainActivity extends AppCompatActivity {
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_main);
15 |
16 | findViewById(R.id.btn_sample).setOnClickListener(new View.OnClickListener() {
17 | @Override
18 | public void onClick(View v) {
19 | Intent intent = new Intent(MainActivity.this,SampleActivity.class);
20 | startActivity(intent);
21 | }
22 | });
23 |
24 | findViewById(R.id.btn_sticky).setOnClickListener(new View.OnClickListener() {
25 | @Override
26 | public void onClick(View v) {
27 | Intent intent = new Intent(MainActivity.this,StickyActivity.class);
28 | startActivity(intent);
29 | }
30 | });
31 |
32 | findViewById(R.id.btn_sink_sticky).setOnClickListener(new View.OnClickListener() {
33 | @Override
34 | public void onClick(View v) {
35 | Intent intent = new Intent(MainActivity.this,SinkStickyActivity.class);
36 | startActivity(intent);
37 | }
38 | });
39 |
40 | findViewById(R.id.btn_consecutive).setOnClickListener(new View.OnClickListener() {
41 | @Override
42 | public void onClick(View v) {
43 | Intent intent = new Intent(MainActivity.this,ConsecutiveActivity.class);
44 | startActivity(intent);
45 | }
46 | });
47 |
48 | findViewById(R.id.btn_scroll_child).setOnClickListener(new View.OnClickListener() {
49 | @Override
50 | public void onClick(View v) {
51 | Intent intent = new Intent(MainActivity.this,ScrollChildActivity.class);
52 | startActivity(intent);
53 | }
54 | });
55 |
56 | findViewById(R.id.btn_viewpager).setOnClickListener(new View.OnClickListener() {
57 | @Override
58 | public void onClick(View v) {
59 | Intent intent = new Intent(MainActivity.this,ViewPagerActivity.class);
60 | startActivity(intent);
61 | }
62 | });
63 |
64 | findViewById(R.id.btn_viewpager2).setOnClickListener(new View.OnClickListener() {
65 | @Override
66 | public void onClick(View v) {
67 | Intent intent = new Intent(MainActivity.this,ViewPager2Activity.class);
68 | startActivity(intent);
69 | }
70 | });
71 |
72 | findViewById(R.id.btn_sticky_permanent).setOnClickListener(new View.OnClickListener() {
73 | @Override
74 | public void onClick(View v) {
75 | Intent intent = new Intent(MainActivity.this, PermanentStickyActivity.class);
76 | startActivity(intent);
77 | }
78 | });
79 |
80 | findViewById(R.id.btn_fragment).setOnClickListener(new View.OnClickListener() {
81 | @Override
82 | public void onClick(View v) {
83 | Intent intent = new Intent(MainActivity.this, FragmentActivity.class);
84 | startActivity(intent);
85 | }
86 | });
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/donkingliang/consecutivescrollerdemo/MyFragment.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescrollerdemo;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | import androidx.annotation.NonNull;
9 | import androidx.annotation.Nullable;
10 | import androidx.fragment.app.Fragment;
11 | import androidx.recyclerview.widget.LinearLayoutManager;
12 | import androidx.recyclerview.widget.RecyclerView;
13 |
14 | import com.donkingliang.consecutivescrollerdemo.adapter.RecyclerViewAdapter;
15 | import com.scwang.smart.refresh.layout.SmartRefreshLayout;
16 |
17 | /**
18 | * @Author donkingliang
19 | * @Description
20 | * @Date 2020/4/18
21 | */
22 | public class MyFragment extends Fragment {
23 |
24 | @Nullable
25 | @Override
26 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
27 |
28 | View view = inflater.inflate(R.layout.fragment_my,container,false);
29 |
30 | RecyclerView recyclerView1 = view.findViewById(R.id.recyclerView1);
31 | recyclerView1.setLayoutManager(new LinearLayoutManager(getActivity()));
32 | RecyclerViewAdapter adapter1 = new RecyclerViewAdapter(getActivity(),"RecyclerView1-");
33 | recyclerView1.setAdapter(adapter1);
34 |
35 | RecyclerView recyclerView2 = view.findViewById(R.id.recyclerView2);
36 | recyclerView2.setLayoutManager(new LinearLayoutManager(getActivity()));
37 | RecyclerViewAdapter adapter2 = new RecyclerViewAdapter(getActivity(),"RecyclerView2-");
38 | recyclerView2.setAdapter(adapter2);
39 | return view;
40 |
41 | }
42 |
43 | public void onLoadMore(final SmartRefreshLayout layout){
44 | // 模拟加载5秒钟
45 | layout.finishLoadMore(5000);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/donkingliang/consecutivescrollerdemo/PermanentStickyActivity.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescrollerdemo;
2 |
3 | import android.os.Bundle;
4 | import android.util.Log;
5 | import android.view.View;
6 | import android.webkit.WebChromeClient;
7 | import android.webkit.WebView;
8 |
9 | import androidx.annotation.NonNull;
10 | import androidx.appcompat.app.AppCompatActivity;
11 | import androidx.recyclerview.widget.LinearLayoutManager;
12 | import androidx.recyclerview.widget.RecyclerView;
13 |
14 | import com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout;
15 | import com.donkingliang.consecutivescrollerdemo.adapter.RecyclerViewAdapter;
16 |
17 | import java.util.List;
18 |
19 | public class PermanentStickyActivity extends AppCompatActivity {
20 |
21 | private ConsecutiveScrollerLayout scrollerLayout;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_sticky_permanent);
27 |
28 | scrollerLayout = findViewById(R.id.scrollerLayout);
29 |
30 | WebView webView = findViewById(R.id.webView);
31 | webView.loadUrl("https://github.com/donkingliang");
32 |
33 | webView.setWebChromeClient(new WebChromeClient() {
34 | @Override
35 | public void onProgressChanged(WebView view, int newProgress) {
36 | super.onProgressChanged(view, newProgress);
37 | // 在webView加载的过程中,用户滚动了webView内容,可能会使webView的显示与scrollerLayout断层,
38 | // 需要让scrollerLayout重新检查一下所有View的显示位置
39 | scrollerLayout.checkLayoutChange();
40 | }
41 | });
42 |
43 |
44 | RecyclerView recyclerView1 = findViewById(R.id.recyclerView1);
45 | recyclerView1.setLayoutManager(new LinearLayoutManager(this));
46 | RecyclerViewAdapter adapter1 = new RecyclerViewAdapter(this,"RecyclerView1-");
47 | recyclerView1.setAdapter(adapter1);
48 |
49 | RecyclerView recyclerView2 = findViewById(R.id.recyclerView2);
50 | recyclerView2.setLayoutManager(new LinearLayoutManager(this));
51 | RecyclerViewAdapter adapter2 = new RecyclerViewAdapter(this,"RecyclerView2-");
52 | recyclerView2.setAdapter(adapter2);
53 |
54 | // 监听吸顶view
55 | scrollerLayout.setOnPermanentStickyChangeListener(new ConsecutiveScrollerLayout.OnPermanentStickyChangeListener() {
56 | @Override
57 | public void onStickyChange(@NonNull List mCurrentStickyViews) {
58 | Log.e("eee",mCurrentStickyViews + "");
59 | }
60 | });
61 |
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/java/com/donkingliang/consecutivescrollerdemo/SampleActivity.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescrollerdemo;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 | import androidx.recyclerview.widget.LinearLayoutManager;
5 | import androidx.recyclerview.widget.RecyclerView;
6 |
7 | import android.os.Bundle;
8 | import android.webkit.WebChromeClient;
9 | import android.webkit.WebView;
10 |
11 | import com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout;
12 | import com.donkingliang.consecutivescrollerdemo.adapter.RecyclerViewAdapter;
13 |
14 | public class SampleActivity extends AppCompatActivity {
15 |
16 | private ConsecutiveScrollerLayout scrollerLayout;
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_sample);
22 |
23 | scrollerLayout = findViewById(R.id.scrollerLayout);
24 |
25 | WebView webView = findViewById(R.id.webView);
26 | webView.loadUrl("https://github.com/donkingliang");
27 |
28 | webView.setWebChromeClient(new WebChromeClient() {
29 | @Override
30 | public void onProgressChanged(WebView view, int newProgress) {
31 | super.onProgressChanged(view, newProgress);
32 | // 在webView加载的过程中,用户滚动了webView内容,可能会使webView的显示与scrollerLayout断层,
33 | // 需要让scrollerLayout重新检查一下所有View的显示位置
34 | scrollerLayout.checkLayoutChange();
35 | }
36 | });
37 |
38 |
39 | RecyclerView recyclerView1 = findViewById(R.id.recyclerView1);
40 | recyclerView1.setLayoutManager(new LinearLayoutManager(this));
41 | RecyclerViewAdapter adapter1 = new RecyclerViewAdapter(this,"RecyclerView1-");
42 | recyclerView1.setAdapter(adapter1);
43 |
44 | RecyclerView recyclerView2 = findViewById(R.id.recyclerView2);
45 | recyclerView2.setLayoutManager(new LinearLayoutManager(this));
46 | RecyclerViewAdapter adapter2 = new RecyclerViewAdapter(this,"RecyclerView2-");
47 | recyclerView2.setAdapter(adapter2);
48 |
49 | RecyclerView recyclerView3 = findViewById(R.id.recyclerView3);
50 | recyclerView3.setLayoutManager(new LinearLayoutManager(this));
51 | RecyclerViewAdapter adapter3 = new RecyclerViewAdapter(this,"RecyclerView3-");
52 | recyclerView3.setAdapter(adapter3);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/app/src/main/java/com/donkingliang/consecutivescrollerdemo/ScrollChildActivity.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescrollerdemo;
2 |
3 | import android.os.Bundle;
4 |
5 | import com.donkingliang.consecutivescrollerdemo.adapter.RecyclerViewAdapter;
6 |
7 | import androidx.appcompat.app.AppCompatActivity;
8 | import androidx.recyclerview.widget.LinearLayoutManager;
9 | import androidx.recyclerview.widget.RecyclerView;
10 |
11 | public class ScrollChildActivity extends AppCompatActivity {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_scroll_child);
17 |
18 | RecyclerView recyclerView1 = findViewById(R.id.recyclerView1);
19 | recyclerView1.setLayoutManager(new LinearLayoutManager(this));
20 | RecyclerViewAdapter adapter1 = new RecyclerViewAdapter(this,"RecyclerView1-");
21 | recyclerView1.setAdapter(adapter1);
22 |
23 | RecyclerView recyclerView2 = findViewById(R.id.recyclerView2);
24 | recyclerView2.setLayoutManager(new LinearLayoutManager(this));
25 | RecyclerViewAdapter adapter2 = new RecyclerViewAdapter(this,"RecyclerView2-");
26 | recyclerView2.setAdapter(adapter2);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/donkingliang/consecutivescrollerdemo/SinkStickyActivity.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescrollerdemo;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 | import android.widget.FrameLayout;
6 |
7 | import com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout;
8 | import com.donkingliang.consecutivescrollerdemo.adapter.RecyclerViewAdapter;
9 |
10 | import androidx.appcompat.app.AppCompatActivity;
11 | import androidx.recyclerview.widget.LinearLayoutManager;
12 | import androidx.recyclerview.widget.RecyclerView;
13 |
14 | public class SinkStickyActivity extends AppCompatActivity {
15 |
16 | private ConsecutiveScrollerLayout scrollerLayout;
17 | private FrameLayout flSink;
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_sink_sticky);
23 |
24 | scrollerLayout = findViewById(R.id.scrollerLayout);
25 |
26 | flSink = findViewById(R.id.fl_sink);
27 |
28 | RecyclerView recyclerView1 = findViewById(R.id.recyclerView1);
29 | recyclerView1.setLayoutManager(new LinearLayoutManager(this));
30 | RecyclerViewAdapter adapter1 = new RecyclerViewAdapter(this,"RecyclerView1-");
31 | recyclerView1.setAdapter(adapter1);
32 |
33 | RecyclerView recyclerView2 = findViewById(R.id.recyclerView2);
34 | recyclerView2.setLayoutManager(new LinearLayoutManager(this));
35 | RecyclerViewAdapter adapter2 = new RecyclerViewAdapter(this,"RecyclerView2-");
36 | recyclerView2.setAdapter(adapter2);
37 |
38 | // 监听滑动
39 | scrollerLayout.setOnVerticalScrollChangeListener(new ConsecutiveScrollerLayout.OnScrollChangeListener() {
40 | @Override
41 | public void onScrollChange(View v, int scrollY, int oldScrollY, int scrollState) {
42 | if (scrollY > flSink.getHeight() || scrollY < 0){
43 | scrollerLayout.setStickyOffset(0); // 恢复吸顶偏移量
44 | } else {
45 | // 通过设置吸顶便宜量,实现flSink滑动隐藏时的向上移动效果
46 | scrollerLayout.setStickyOffset(-scrollY / 2);
47 | }
48 | }
49 | });
50 |
51 |
52 | // 如果flSink不需要设置隐藏时的平移动画,就不用设置滑动监听和setStickyOffset
53 |
54 | // 如果要禁止滑动flSink来滑动整个布局,flSink不用设置app:layout_isTriggerScroll="true"即可。
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/donkingliang/consecutivescrollerdemo/StickyActivity.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescrollerdemo;
2 |
3 | import androidx.annotation.Nullable;
4 | import androidx.appcompat.app.AppCompatActivity;
5 | import androidx.recyclerview.widget.LinearLayoutManager;
6 | import androidx.recyclerview.widget.RecyclerView;
7 |
8 | import android.os.Bundle;
9 | import android.util.Log;
10 | import android.view.View;
11 | import android.webkit.WebChromeClient;
12 | import android.webkit.WebView;
13 |
14 | import com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout;
15 | import com.donkingliang.consecutivescrollerdemo.adapter.RecyclerViewAdapter;
16 |
17 | public class StickyActivity extends AppCompatActivity {
18 |
19 | private ConsecutiveScrollerLayout scrollerLayout;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_sticky);
25 |
26 | scrollerLayout = findViewById(R.id.scrollerLayout);
27 |
28 | WebView webView = findViewById(R.id.webView);
29 | webView.loadUrl("https://github.com/donkingliang");
30 |
31 | webView.setWebChromeClient(new WebChromeClient() {
32 | @Override
33 | public void onProgressChanged(WebView view, int newProgress) {
34 | super.onProgressChanged(view, newProgress);
35 | // 在webView加载的过程中,用户滚动了webView内容,可能会使webView的显示与scrollerLayout断层,
36 | // 需要让scrollerLayout重新检查一下所有View的显示位置
37 | scrollerLayout.checkLayoutChange();
38 | }
39 | });
40 |
41 |
42 | RecyclerView recyclerView1 = findViewById(R.id.recyclerView1);
43 | recyclerView1.setLayoutManager(new LinearLayoutManager(this));
44 | RecyclerViewAdapter adapter1 = new RecyclerViewAdapter(this,"RecyclerView1-");
45 | recyclerView1.setAdapter(adapter1);
46 |
47 | RecyclerView recyclerView2 = findViewById(R.id.recyclerView2);
48 | recyclerView2.setLayoutManager(new LinearLayoutManager(this));
49 | RecyclerViewAdapter adapter2 = new RecyclerViewAdapter(this,"RecyclerView2-");
50 | recyclerView2.setAdapter(adapter2);
51 |
52 | // 监听吸顶view
53 | scrollerLayout.setOnStickyChangeListener(new ConsecutiveScrollerLayout.OnStickyChangeListener() {
54 | @Override
55 | public void onStickyChange(@Nullable View oldStickyView, @Nullable View newStickyView) {
56 | Log.e("eee",oldStickyView + " " + newStickyView);
57 | }
58 | });
59 |
60 |
61 | // 设置吸顶到顶部的距离
62 | // scrollerLayout.setStickyOffset(50);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/java/com/donkingliang/consecutivescrollerdemo/ViewPager2Activity.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescrollerdemo;
2 |
3 | import android.os.Bundle;
4 | import android.widget.TextView;
5 |
6 | import com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout;
7 | import com.donkingliang.consecutivescroller.ConsecutiveViewPager2;
8 | import com.donkingliang.consecutivescrollerdemo.adapter.MyFragmentPagerAdapter;
9 | import com.google.android.material.tabs.TabLayout;
10 | import com.google.android.material.tabs.TabLayoutMediator;
11 | import com.scwang.smart.refresh.layout.SmartRefreshLayout;
12 | import com.scwang.smart.refresh.layout.api.RefreshFooter;
13 | import com.scwang.smart.refresh.layout.api.RefreshLayout;
14 | import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;
15 | import com.scwang.smart.refresh.layout.simple.SimpleMultiListener;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | import androidx.annotation.NonNull;
21 | import androidx.appcompat.app.AppCompatActivity;
22 | import androidx.fragment.app.Fragment;
23 |
24 | public class ViewPager2Activity extends AppCompatActivity {
25 |
26 | private ConsecutiveScrollerLayout scrollerLayout;
27 | private ConsecutiveViewPager2 viewPager2;
28 | private TabLayout tabLayout;
29 | private SmartRefreshLayout refreshLayout;
30 |
31 | private MyFragmentPagerAdapter mAdapter;
32 |
33 | private List fragments;
34 |
35 | @Override
36 | protected void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 | setContentView(R.layout.activity_viewpager2);
39 |
40 | TextView text = findViewById(R.id.text);
41 | text.setText("子view通过实现IConsecutiveScroller接口,可以使ConsecutiveScrollerLayout能正确地处理子view的下级view的滑动事件。\n" +
42 | "下面的例子中,通过自定义ViewPager,实现IConsecutiveScroller接口,ConsecutiveScrollerLayout能正确的处理ViewPager里" +
43 | "的子布局。如果ViewPager的内容是可以垂直滑动的,请使用ConsecutiveScrollerLayout或者RecyclerView等可滑动布局作为它内容的根布局。\n" +
44 | "下面的列子中使用ViewPager承载多个Fragment,Fragment的根布局为ConsecutiveScrollerLayout。");
45 | scrollerLayout = findViewById(R.id.scrollerLayout);
46 | viewPager2 = findViewById(R.id.viewPager2);
47 | tabLayout = findViewById(R.id.tabLayout);
48 | refreshLayout = findViewById(R.id.refreshLayout);
49 |
50 | fragments = getFragments();
51 |
52 | mAdapter = new MyFragmentPagerAdapter(this, fragments);
53 |
54 | viewPager2.setAdapter(mAdapter);
55 |
56 | new TabLayoutMediator(tabLayout, viewPager2.getViewPager2(), new TabLayoutMediator.TabConfigurationStrategy() {
57 | @Override
58 | public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
59 | tab.setText("Tab" + (position + 1));
60 | }
61 | }).attach();
62 |
63 | refreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
64 | @Override
65 | public void onLoadMore(@NonNull RefreshLayout r) {
66 | // 把加载的动作传给当初的fragment
67 | MyFragment fragment = (MyFragment) fragments.get(viewPager2.getCurrentItem());
68 | fragment.onLoadMore(refreshLayout);
69 | }
70 |
71 | @Override
72 | public void onRefresh(@NonNull RefreshLayout r) {
73 | refreshLayout.finishRefresh(5000);
74 | }
75 | });
76 |
77 | refreshLayout.setOnMultiListener(new SimpleMultiListener() {
78 | @Override
79 | public void onFooterMoving(RefreshFooter footer, boolean isDragging, float percent, int offset, int footerHeight, int maxDragHeight) {
80 | // 上拉加载时,保证吸顶头部不被推出屏幕。
81 | scrollerLayout.setStickyOffset(offset);
82 | }
83 | });
84 | }
85 |
86 | // 提供给Fragment获取使用。
87 | public SmartRefreshLayout getRefreshLayout() {
88 | return refreshLayout;
89 | }
90 |
91 | private List getFragments() {
92 | List fragmentList = new ArrayList<>();
93 | fragmentList.add(new MyFragment());
94 | fragmentList.add(new MyFragment());
95 | fragmentList.add(new MyFragment());
96 | fragmentList.add(new MyFragment());
97 | fragmentList.add(new MyFragment());
98 | return fragmentList;
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/app/src/main/java/com/donkingliang/consecutivescrollerdemo/ViewPagerActivity.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescrollerdemo;
2 |
3 | import android.os.Bundle;
4 | import android.util.Log;
5 | import android.widget.TextView;
6 |
7 | import com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout;
8 | import com.donkingliang.consecutivescroller.ConsecutiveViewPager;
9 | import com.donkingliang.consecutivescrollerdemo.adapter.TabPagerAdapter;
10 | import com.google.android.material.tabs.TabLayout;
11 | import com.scwang.smart.refresh.layout.SmartRefreshLayout;
12 | import com.scwang.smart.refresh.layout.api.RefreshFooter;
13 | import com.scwang.smart.refresh.layout.api.RefreshLayout;
14 | import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;
15 | import com.scwang.smart.refresh.layout.simple.SimpleMultiListener;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | import androidx.annotation.NonNull;
21 | import androidx.appcompat.app.AppCompatActivity;
22 | import androidx.fragment.app.Fragment;
23 |
24 | public class ViewPagerActivity extends AppCompatActivity {
25 |
26 | private ConsecutiveScrollerLayout scrollerLayout;
27 | private ConsecutiveViewPager viewPager;
28 | private TabLayout tabLayout;
29 | private SmartRefreshLayout refreshLayout;
30 |
31 | private TabPagerAdapter mAdapter;
32 |
33 | @Override
34 | protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.activity_viewpager);
37 |
38 | TextView text = findViewById(R.id.text);
39 | text.setText("子view通过实现IConsecutiveScroller接口,可以使ConsecutiveScrollerLayout能正确地处理子view的下级view的滑动事件。\n" +
40 | "下面的例子中,通过自定义ViewPager,实现IConsecutiveScroller接口,ConsecutiveScrollerLayout能正确的处理ViewPager里" +
41 | "的子布局。如果ViewPager的内容是可以垂直滑动的,请使用ConsecutiveScrollerLayout或者RecyclerView等可滑动布局作为它内容的根布局。\n" +
42 | "下面的列子中使用ViewPager承载多个Fragment,Fragment的根布局为ConsecutiveScrollerLayout。");
43 | scrollerLayout = findViewById(R.id.scrollerLayout);
44 | viewPager = findViewById(R.id.viewPager);
45 | tabLayout = findViewById(R.id.tabLayout);
46 | refreshLayout = findViewById(R.id.refreshLayout);
47 |
48 | mAdapter = new TabPagerAdapter(getSupportFragmentManager(), getTabs(), getFragments());
49 | viewPager.setAdapter(mAdapter);
50 | tabLayout.setupWithViewPager(viewPager);
51 |
52 | refreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
53 | @Override
54 | public void onLoadMore(@NonNull RefreshLayout r) {
55 | // 把加载的动作传给当初的fragment
56 | MyFragment fragment = (MyFragment) mAdapter.getItem(viewPager.getCurrentItem());
57 | fragment.onLoadMore(refreshLayout);
58 | }
59 |
60 | @Override
61 | public void onRefresh(@NonNull RefreshLayout r) {
62 | refreshLayout.finishRefresh(5000);
63 | }
64 | });
65 |
66 | refreshLayout.setOnMultiListener(new SimpleMultiListener() {
67 | @Override
68 | public void onFooterMoving(RefreshFooter footer, boolean isDragging, float percent, int offset, int footerHeight, int maxDragHeight) {
69 | // 上拉加载时,保证吸顶头部不被推出屏幕。
70 | Log.e("eee","****" + offset);
71 | scrollerLayout.setStickyOffset(offset);
72 | }
73 | });
74 | }
75 |
76 | // 提供给Fragment获取使用。
77 | public SmartRefreshLayout getRefreshLayout() {
78 | return refreshLayout;
79 | }
80 |
81 | private List getTabs() {
82 | List tabs = new ArrayList<>();
83 | tabs.add("Tab1");
84 | tabs.add("Tab2");
85 | tabs.add("Tab3");
86 | tabs.add("Tab4");
87 | tabs.add("Tab5");
88 | return tabs;
89 | }
90 |
91 | private List getFragments() {
92 | List fragmentList = new ArrayList<>();
93 | fragmentList.add(new MyFragment());
94 | fragmentList.add(new MyFragment());
95 | fragmentList.add(new MyFragment());
96 | fragmentList.add(new MyFragment());
97 | fragmentList.add(new MyFragment());
98 | return fragmentList;
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/app/src/main/java/com/donkingliang/consecutivescrollerdemo/adapter/MyFragmentPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescrollerdemo.adapter;
2 |
3 | import java.util.List;
4 |
5 | import androidx.annotation.NonNull;
6 | import androidx.fragment.app.Fragment;
7 | import androidx.fragment.app.FragmentActivity;
8 | import androidx.viewpager2.adapter.FragmentStateAdapter;
9 |
10 | /**
11 | * @Author donkingliang
12 | * @Description
13 | * @Date 2020/11/5
14 | */
15 | public class MyFragmentPagerAdapter extends FragmentStateAdapter {
16 |
17 | private List extends Fragment> mFragments;
18 |
19 | public MyFragmentPagerAdapter(@NonNull FragmentActivity fragmentActivity, List extends Fragment> fragments) {
20 | super(fragmentActivity);
21 | this.mFragments = fragments;
22 | }
23 |
24 | @NonNull
25 | @Override
26 | public Fragment createFragment(int position) {
27 | return mFragments.get(position);
28 | }
29 |
30 | @Override
31 | public int getItemCount() {
32 | return mFragments.size();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/donkingliang/consecutivescrollerdemo/adapter/RecyclerViewAdapter.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescrollerdemo.adapter;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 | import android.widget.Toast;
9 |
10 | import com.donkingliang.consecutivescrollerdemo.R;
11 |
12 | import androidx.recyclerview.widget.RecyclerView;
13 |
14 | /**
15 | * @Author donkingliang
16 | * @Description
17 | * @Date 2020/3/17
18 | */
19 | public class RecyclerViewAdapter extends RecyclerView.Adapter {
20 |
21 | private Context context;
22 | private String text;
23 | private int count = 30;
24 |
25 | public RecyclerViewAdapter(Context context, String text) {
26 | this.context = context;
27 | this.text = text;
28 | }
29 |
30 | @Override
31 | public int getItemCount() {
32 | return count;
33 | }
34 |
35 | public int getCount() {
36 | return count;
37 | }
38 |
39 | public void setCount(int count) {
40 | this.count = count;
41 | notifyDataSetChanged();
42 | }
43 |
44 | @Override
45 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
46 | View view = LayoutInflater.from(context).inflate(R.layout.adapter_recycler_item, parent, false);
47 | return new ViewHolder(view);
48 | }
49 |
50 | @Override
51 | public void onBindViewHolder(final ViewHolder holder, final int position) {
52 | holder.textView.setText(text + (position + 1));
53 | holder.textView.setOnClickListener(new View.OnClickListener() {
54 | @Override
55 | public void onClick(View v) {
56 | Toast.makeText(context,holder.textView.getText().toString(),Toast.LENGTH_SHORT).show();
57 | }
58 | });
59 | }
60 |
61 | public static class ViewHolder extends RecyclerView.ViewHolder {
62 |
63 | TextView textView;
64 |
65 | public ViewHolder(View itemView) {
66 | super(itemView);
67 |
68 | textView = itemView.findViewById(R.id.textView);
69 | }
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/app/src/main/java/com/donkingliang/consecutivescrollerdemo/adapter/TabPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescrollerdemo.adapter;
2 |
3 |
4 | import java.util.List;
5 |
6 | import androidx.fragment.app.Fragment;
7 | import androidx.fragment.app.FragmentManager;
8 | import androidx.fragment.app.FragmentStatePagerAdapter;
9 |
10 | /**
11 | * Depiction: TabLayout 和 Fragment,viewpager结合使用的viewpager adapter。
12 | */
13 | public class TabPagerAdapter extends FragmentStatePagerAdapter {
14 |
15 | private List mTitles;
16 | private List extends Fragment> mFragments;
17 |
18 | public TabPagerAdapter(FragmentManager fm, List titleList, List extends Fragment> fragments) {
19 | super(fm);
20 | this.mTitles = titleList;
21 | this.mFragments = fragments;
22 | }
23 |
24 | @Override
25 | public Fragment getItem(int position) {
26 | return mFragments.get(position);
27 | }
28 |
29 | @Override
30 | public int getCount() {
31 | return mFragments == null ? 0 : mFragments.size();
32 | }
33 |
34 | @Override
35 | public CharSequence getPageTitle(int position) {
36 | return mTitles == null ? "" : mTitles.get(position);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/donkingliang/consecutivescrollerdemo/view/MyFrameLayout.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescrollerdemo.view;
2 |
3 | import android.content.Context;
4 | import android.os.Build;
5 | import android.util.AttributeSet;
6 | import android.view.View;
7 | import android.widget.FrameLayout;
8 |
9 | import com.donkingliang.consecutivescroller.IConsecutiveScroller;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | import androidx.annotation.NonNull;
15 | import androidx.annotation.Nullable;
16 | import androidx.annotation.RequiresApi;
17 |
18 | /**
19 | * @Author teach liang
20 | * @Description
21 | * @Date 2021/5/17
22 | */
23 | public class MyFrameLayout extends FrameLayout implements IConsecutiveScroller {
24 |
25 | public MyFrameLayout(@NonNull Context context) {
26 | super(context);
27 | }
28 |
29 | public MyFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
30 | super(context, attrs);
31 | }
32 |
33 | public MyFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
34 | super(context, attrs, defStyleAttr);
35 | }
36 |
37 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
38 | public MyFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
39 | super(context, attrs, defStyleAttr, defStyleRes);
40 | }
41 |
42 | @Override
43 | public View getCurrentScrollerView() {
44 | // 返回需要滑动的ScrollView
45 | return getChildAt(0);
46 | }
47 |
48 | @Override
49 | public List getScrolledViews() {
50 | // 返回需要滑动的ScrollView
51 | List views = new ArrayList<>();
52 | views.add(getChildAt(0));
53 | return views;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/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/drawable-xhdpi/temp.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donkingliang/ConsecutiveScroller/bad427106fa54044b22c632d9f3a7a546bd9f7e3/app/src/main/res/drawable-xhdpi/temp.jpg
--------------------------------------------------------------------------------
/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/layout/activity_consecutive.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
23 |
24 |
31 |
32 |
40 |
41 |
42 |
43 |
50 |
51 |
54 |
55 |
59 |
60 |
64 |
65 |
69 |
70 |
74 |
75 |
79 |
80 |
84 |
85 |
89 |
90 |
94 |
95 |
99 |
100 |
104 |
105 |
109 |
110 |
114 |
115 |
119 |
120 |
124 |
125 |
129 |
130 |
131 |
132 |
133 |
134 |
141 |
142 |
147 |
148 |
154 |
155 |
162 |
163 |
170 |
171 |
178 |
179 |
186 |
187 |
194 |
195 |
202 |
203 |
204 |
205 |
206 |
210 |
211 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
20 |
21 |
28 |
29 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
18 |
19 |
24 |
25 |
30 |
31 |
36 |
37 |
42 |
43 |
49 |
50 |
56 |
57 |
63 |
64 |
70 |
71 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_sample.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
22 |
23 |
24 |
27 |
28 |
29 |
37 |
38 |
44 |
45 |
46 |
47 |
48 |
51 |
52 |
55 |
56 |
62 |
63 |
70 |
71 |
78 |
79 |
86 |
87 |
94 |
95 |
102 |
103 |
110 |
111 |
112 |
113 |
114 |
118 |
119 |
124 |
125 |
128 |
129 |
135 |
136 |
143 |
144 |
151 |
152 |
159 |
160 |
167 |
168 |
175 |
176 |
183 |
184 |
185 |
186 |
187 |
191 |
192 |
196 |
197 |
204 |
205 |
209 |
210 |
211 |
212 |
213 |
214 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_scroll_child.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
24 |
25 |
29 |
30 |
31 |
35 |
36 |
37 |
38 |
45 |
46 |
49 |
50 |
51 |
55 |
56 |
57 |
58 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_sink_sticky.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
18 |
19 |
24 |
25 |
34 |
35 |
36 |
37 |
46 |
47 |
52 |
53 |
62 |
63 |
66 |
67 |
73 |
74 |
81 |
82 |
89 |
90 |
97 |
98 |
105 |
106 |
113 |
114 |
121 |
122 |
123 |
124 |
125 |
134 |
135 |
140 |
141 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_sticky.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
20 |
21 |
25 |
26 |
32 |
33 |
40 |
41 |
42 |
43 |
47 |
48 |
57 |
58 |
61 |
62 |
68 |
69 |
76 |
77 |
84 |
85 |
92 |
93 |
100 |
101 |
108 |
109 |
116 |
117 |
118 |
119 |
120 |
129 |
130 |
134 |
135 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_sticky_permanent.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
21 |
22 |
26 |
27 |
33 |
34 |
41 |
42 |
43 |
44 |
48 |
49 |
58 |
59 |
62 |
63 |
69 |
70 |
77 |
78 |
85 |
86 |
93 |
94 |
101 |
102 |
109 |
110 |
117 |
118 |
119 |
120 |
121 |
122 |
131 |
132 |
136 |
137 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_viewpager.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
18 |
19 |
27 |
28 |
39 |
40 |
44 |
45 |
46 |
47 |
50 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_viewpager2.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
18 |
19 |
27 |
28 |
39 |
40 |
44 |
45 |
46 |
47 |
50 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/adapter_recycler_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_my.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
13 |
14 |
15 |
18 |
19 |
20 |
28 |
29 |
35 |
36 |
37 |
38 |
39 |
42 |
43 |
46 |
47 |
53 |
54 |
61 |
62 |
69 |
70 |
77 |
78 |
85 |
86 |
93 |
94 |
101 |
102 |
103 |
104 |
105 |
109 |
110 |
115 |
116 |
119 |
120 |
126 |
127 |
134 |
135 |
142 |
143 |
150 |
151 |
158 |
159 |
166 |
167 |
174 |
175 |
176 |
177 |
178 |
182 |
183 |
184 |
185 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donkingliang/ConsecutiveScroller/bad427106fa54044b22c632d9f3a7a546bd9f7e3/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donkingliang/ConsecutiveScroller/bad427106fa54044b22c632d9f3a7a546bd9f7e3/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donkingliang/ConsecutiveScroller/bad427106fa54044b22c632d9f3a7a546bd9f7e3/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donkingliang/ConsecutiveScroller/bad427106fa54044b22c632d9f3a7a546bd9f7e3/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donkingliang/ConsecutiveScroller/bad427106fa54044b22c632d9f3a7a546bd9f7e3/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donkingliang/ConsecutiveScroller/bad427106fa54044b22c632d9f3a7a546bd9f7e3/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donkingliang/ConsecutiveScroller/bad427106fa54044b22c632d9f3a7a546bd9f7e3/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donkingliang/ConsecutiveScroller/bad427106fa54044b22c632d9f3a7a546bd9f7e3/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donkingliang/ConsecutiveScroller/bad427106fa54044b22c632d9f3a7a546bd9f7e3/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donkingliang/ConsecutiveScroller/bad427106fa54044b22c632d9f3a7a546bd9f7e3/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ConsecutiveScroller
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/donkingliang/consecutivescrollerdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescrollerdemo;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | google()
6 | jcenter()
7 |
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:4.2.2'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | google()
20 | jcenter()
21 |
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/consecutivescroller/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/consecutivescroller/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | group='com.github.donkingliang' // 指定group,com.github.<用户名>
4 |
5 | android {
6 | compileSdkVersion 30
7 | defaultConfig {
8 | minSdkVersion 19
9 | targetSdkVersion 30
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14 | consumerProguardFiles 'consumer-rules.pro'
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 | compileOnly 'androidx.appcompat:appcompat:1.3.1'
29 | compileOnly 'androidx.recyclerview:recyclerview:1.2.1'
30 | compileOnly 'androidx.viewpager2:viewpager2:1.1.0-alpha01'
31 | }
32 |
33 | //---------------------------------------------
34 |
35 | // 指定编码
36 | tasks.withType(JavaCompile) {
37 | options.encoding = "UTF-8"
38 | }
39 |
40 | // 打包源码
41 | task sourcesJar(type: Jar) {
42 | from android.sourceSets.main.java.srcDirs
43 | classifier = 'sources'
44 | }
45 |
46 | task javadoc(type: Javadoc) {
47 | failOnError false
48 | source = android.sourceSets.main.java.sourceFiles
49 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
50 | classpath += configurations.compile
51 | }
52 |
53 | artifacts {
54 | archives sourcesJar
55 | }
--------------------------------------------------------------------------------
/consecutivescroller/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donkingliang/ConsecutiveScroller/bad427106fa54044b22c632d9f3a7a546bd9f7e3/consecutivescroller/consumer-rules.pro
--------------------------------------------------------------------------------
/consecutivescroller/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 |
--------------------------------------------------------------------------------
/consecutivescroller/src/androidTest/java/com/donkingliang/consecutivescroller/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescroller;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 |
25 | assertEquals("com.donkingliang.consecutivescroller.test", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/consecutivescroller/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/consecutivescroller/src/main/java/com/donkingliang/consecutivescroller/ConsecutiveViewPager.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescroller;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.view.ViewParent;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | import androidx.annotation.NonNull;
13 | import androidx.annotation.Nullable;
14 | import androidx.core.view.ViewCompat;
15 | import androidx.viewpager.widget.ViewPager;
16 |
17 | /**
18 | * @Author donkingliang
19 | * @Description
20 | * @Date 2020/5/22
21 | */
22 | public class ConsecutiveViewPager extends ViewPager implements IConsecutiveScroller {
23 |
24 | private int mAdjustHeight;
25 |
26 | public ConsecutiveViewPager(@NonNull Context context) {
27 | super(context);
28 | }
29 |
30 | public ConsecutiveViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
31 | super(context, attrs);
32 | }
33 |
34 | @Override
35 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
36 | if (isConsecutiveParentAndBottom() && mAdjustHeight > 0) {
37 | int height = getDefaultSize(0, heightMeasureSpec) - mAdjustHeight;
38 | super.onMeasure(widthMeasureSpec,
39 | MeasureSpec.makeMeasureSpec(height, MeasureSpec.getMode(heightMeasureSpec)));
40 | } else {
41 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
42 | }
43 | }
44 |
45 | @Override
46 | public void addView(View child, int index, ViewGroup.LayoutParams params) {
47 | super.addView(child, index, params);
48 |
49 | // 去掉子View的滚动条。选择在这里做这个操作,而不是在onFinishInflate方法中完成,是为了兼顾用代码add子View的情况
50 |
51 | if (ScrollUtils.isConsecutiveScrollerChild(this)) {
52 | disableChildScroll(child);
53 |
54 | if (child instanceof ViewGroup) {
55 | ((ViewGroup) child).setClipToPadding(false);
56 | }
57 | }
58 | }
59 |
60 | /**
61 | * 禁用子view的一下滑动相关的属性
62 | *
63 | * @param child
64 | */
65 | private void disableChildScroll(View child) {
66 | child.setVerticalScrollBarEnabled(false);
67 | child.setHorizontalScrollBarEnabled(false);
68 | child.setOverScrollMode(OVER_SCROLL_NEVER);
69 | ViewCompat.setNestedScrollingEnabled(child, false);
70 | }
71 |
72 | /**
73 | * 是否在ConsecutiveScrollerLayout的底部
74 | *
75 | * @return
76 | */
77 | private boolean isConsecutiveParentAndBottom() {
78 | ViewParent parent = getParent();
79 | if (parent instanceof ConsecutiveScrollerLayout) {
80 | ConsecutiveScrollerLayout layout = (ConsecutiveScrollerLayout) parent;
81 | return layout.indexOfChild(this) == layout.getChildCount() - 1;
82 | }
83 | return false;
84 | }
85 |
86 | /**
87 | * @deprecated
88 | */
89 | public int getAdjustHeight() {
90 | return mAdjustHeight;
91 | }
92 |
93 | /**
94 | * @deprecated 如果你想调整ViewPager的高度,使它不被顶部吸顶view或者其他布局覆盖,
95 | * 请使用ConsecutiveScrollerLayout的autoAdjustHeightAtBottomView和adjustHeightOffset属性。
96 | */
97 | public void setAdjustHeight(int adjustHeight) {
98 | if (mAdjustHeight != adjustHeight) {
99 | mAdjustHeight = adjustHeight;
100 | requestLayout();
101 | }
102 | }
103 |
104 | /**
105 | * 返回当前需要滑动的view。
106 | *
107 | * @return
108 | */
109 | @Override
110 | public View getCurrentScrollerView() {
111 | int count = getChildCount();
112 | for (int i = 0; i < count; i++) {
113 | View view = getChildAt(i);
114 | if (view.getX() == getScrollX() + getPaddingLeft()) {
115 | return view;
116 | }
117 | }
118 | return this;
119 | }
120 |
121 | /**
122 | * 返回全部需要滑动的下级view
123 | *
124 | * @return
125 | */
126 | @Override
127 | public List getScrolledViews() {
128 | List views = new ArrayList<>();
129 | int count = getChildCount();
130 | if (count > 0) {
131 | for (int i = 0; i < count; i++) {
132 | views.add(getChildAt(i));
133 | }
134 | }
135 | return views;
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/consecutivescroller/src/main/java/com/donkingliang/consecutivescroller/ConsecutiveViewPager2.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescroller;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.view.ViewParent;
8 | import android.widget.FrameLayout;
9 |
10 | import java.lang.ref.WeakReference;
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | import androidx.annotation.NonNull;
15 | import androidx.annotation.Nullable;
16 | import androidx.recyclerview.widget.RecyclerView;
17 | import androidx.recyclerview.widget.RecyclerView.Adapter;
18 | import androidx.recyclerview.widget.RecyclerView.LayoutManager;
19 | import androidx.viewpager2.adapter.FragmentStateAdapter;
20 | import androidx.viewpager2.widget.ViewPager2;
21 |
22 | /**
23 | * @Author donkingliang
24 | * @Description Viewpager2的包装类,它不是ViewPager2的子类,而且一个包含ViewPager2的容器,提供了ViewPager2的所有功能,
25 | * 同时实现IConsecutiveScroller接口,使它能配合ConsecutiveScrollerLayout的滑动处理。
26 | * 因为Viewpager2不能被继承,所有使用包装类的方式来解决Viewpager2和ConsecutiveScrollerLayout的滑动冲突。
27 | * @Date 2020/11/6
28 | */
29 | public class ConsecutiveViewPager2 extends FrameLayout implements IConsecutiveScroller {
30 |
31 | protected ViewPager2 mViewPager2;
32 | protected RecyclerView mRecyclerView;
33 |
34 | private int mAdjustHeight;
35 |
36 | private static final int TAG_KEY = -123;
37 |
38 | public ConsecutiveViewPager2(@NonNull Context context) {
39 | super(context);
40 | initialize(context);
41 | }
42 |
43 | public ConsecutiveViewPager2(@NonNull Context context, @Nullable AttributeSet attrs) {
44 | super(context, attrs);
45 | initialize(context);
46 | }
47 |
48 | public ConsecutiveViewPager2(Context context, AttributeSet attrs, int defStyleAttr) {
49 | super(context, attrs, defStyleAttr);
50 | initialize(context);
51 | }
52 |
53 | private void initialize(Context context) {
54 | mViewPager2 = new ViewPager2(context);
55 | addView(mViewPager2, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
56 | mRecyclerView = (RecyclerView) mViewPager2.getChildAt(0);
57 | }
58 |
59 | @Override
60 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
61 | if (isConsecutiveParentAndBottom() && mAdjustHeight > 0) {
62 | int height = getDefaultSize(0, heightMeasureSpec) - mAdjustHeight;
63 | super.onMeasure(widthMeasureSpec,
64 | MeasureSpec.makeMeasureSpec(height, MeasureSpec.getMode(heightMeasureSpec)));
65 | } else {
66 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
67 | }
68 | }
69 |
70 | /**
71 | * 是否在ConsecutiveScrollerLayout的底部
72 | */
73 | private boolean isConsecutiveParentAndBottom() {
74 | ViewParent parent = getParent();
75 | if (parent instanceof ConsecutiveScrollerLayout) {
76 | ConsecutiveScrollerLayout layout = (ConsecutiveScrollerLayout) parent;
77 | return layout.indexOfChild(this) == layout.getChildCount() - 1;
78 | }
79 | return false;
80 | }
81 |
82 | /**
83 | * @deprecated
84 | */
85 | public int getAdjustHeight() {
86 | return mAdjustHeight;
87 | }
88 |
89 | /**
90 | * @deprecated 如果你想调整ViewPager的高度,使它不被顶部吸顶view或者其他布局覆盖,
91 | * 请使用ConsecutiveScrollerLayout的autoAdjustHeightAtBottomView和adjustHeightOffset属性。
92 | */
93 | public void setAdjustHeight(int adjustHeight) {
94 | if (mAdjustHeight != adjustHeight) {
95 | mAdjustHeight = adjustHeight;
96 | requestLayout();
97 | }
98 | }
99 |
100 | /**
101 | * 返回当前需要滑动的view。
102 | *
103 | * @return
104 | */
105 | @Override
106 | public View getCurrentScrollerView() {
107 | View scrollerView = null;
108 | int currentItem = getCurrentItem();
109 | Adapter adapter = mRecyclerView.getAdapter();
110 | LayoutManager layoutManager = mRecyclerView.getLayoutManager();
111 | if (adapter != null && layoutManager != null) {
112 | if (currentItem >= 0 && currentItem < adapter.getItemCount()) {
113 | View itemView = layoutManager.findViewByPosition(currentItem);
114 | scrollerView = findScrolledItemView(itemView);
115 | if (scrollerView != null) {
116 | setAttachListener(scrollerView);
117 | }
118 | }
119 | }
120 |
121 | if (scrollerView == null) {
122 | scrollerView = mRecyclerView;
123 | }
124 | return scrollerView;
125 | }
126 |
127 | /**
128 | * 给scrollerView添加OnAttachStateChange监听,在item添加到屏幕是检查scrollerView滑动位置,放在布局显示断层。
129 | *
130 | * @param scrollerView
131 | */
132 | private void setAttachListener(View scrollerView) {
133 | if (scrollerView.getTag(TAG_KEY) != null) {
134 | AttachListener listener = (AttachListener) scrollerView.getTag(TAG_KEY);
135 | if (listener.reference.get() == null) {
136 | // 情况原来的监听器
137 | scrollerView.removeOnAttachStateChangeListener(listener);
138 | scrollerView.setTag(TAG_KEY, null);
139 | }
140 | }
141 |
142 | if (scrollerView.getTag(TAG_KEY) == null) {
143 | ViewGroup.LayoutParams lp = getLayoutParams();
144 | if (lp instanceof ConsecutiveScrollerLayout.LayoutParams) {
145 | if (((ConsecutiveScrollerLayout.LayoutParams) lp).isConsecutive) {
146 | AttachListener l = new AttachListener(this, scrollerView);
147 | scrollerView.addOnAttachStateChangeListener(l);
148 | scrollerView.setTag(TAG_KEY, l);
149 | }
150 | }
151 | }
152 | }
153 |
154 | private void scrollChildContent(View v) {
155 | if (v != null && getParent() instanceof ConsecutiveScrollerLayout) {
156 | ConsecutiveScrollerLayout parent = (ConsecutiveScrollerLayout) getParent();
157 | int thisIndex = parent.indexOfChild(this);
158 |
159 | // 判断是否需要滑动内容到底部或顶部
160 |
161 | if (thisIndex == parent.getChildCount() - 1
162 | && getHeight() < parent.getHeight()
163 | && parent.getScrollY() >= parent.mScrollRange) {
164 | return;
165 | }
166 |
167 | View firstVisibleView = parent.findFirstVisibleView();
168 | if (firstVisibleView == null) {
169 | return;
170 | }
171 | int firstIndex = parent.indexOfChild(firstVisibleView);
172 |
173 | if (thisIndex < firstIndex) {
174 | parent.scrollChildContentToBottom(v);
175 | } else if (thisIndex > firstIndex) {
176 | parent.scrollChildContentToTop(v);
177 | }
178 | }
179 | }
180 |
181 | /**
182 | * 返回全部需要滑动的下级view
183 | *
184 | * @return
185 | */
186 | @Override
187 | public List getScrolledViews() {
188 | List views = new ArrayList<>();
189 | int count = mRecyclerView.getChildCount();
190 | if (count > 0) {
191 | for (int i = 0; i < count; i++) {
192 | views.add(findScrolledItemView(mRecyclerView.getChildAt(i)));
193 | }
194 | }
195 | return views;
196 | }
197 |
198 | protected View findScrolledItemView(View view) {
199 | if (mRecyclerView.getAdapter() instanceof FragmentStateAdapter
200 | && view instanceof FrameLayout) {
201 | FrameLayout frameLayout = (FrameLayout) view;
202 | if (frameLayout.getChildCount() > 0) {
203 | return frameLayout.getChildAt(0);
204 | }
205 | }
206 | return view;
207 | }
208 |
209 | public ViewPager2 getViewPager2() {
210 | return mViewPager2;
211 | }
212 |
213 | public void setAdapter(@Nullable @SuppressWarnings("rawtypes") RecyclerView.Adapter adapter) {
214 | mViewPager2.setAdapter(adapter);
215 | }
216 |
217 | public @Nullable
218 | RecyclerView.Adapter getAdapter() {
219 | return mViewPager2.getAdapter();
220 | }
221 |
222 | public void setOrientation(@ViewPager2.Orientation int orientation) {
223 | mViewPager2.setOrientation(orientation);
224 | }
225 |
226 | public @ViewPager2.Orientation
227 | int getOrientation() {
228 | return mViewPager2.getOrientation();
229 | }
230 |
231 | public void setCurrentItem(int item) {
232 | mViewPager2.setCurrentItem(item);
233 | }
234 |
235 | public void setCurrentItem(int item, boolean smoothScroll) {
236 | mViewPager2.setCurrentItem(item, smoothScroll);
237 | }
238 |
239 | public int getCurrentItem() {
240 | return mViewPager2.getCurrentItem();
241 | }
242 |
243 | public void setOffscreenPageLimit(@ViewPager2.OffscreenPageLimit int limit) {
244 | mViewPager2.setOffscreenPageLimit(limit);
245 | }
246 |
247 | @ViewPager2.OffscreenPageLimit
248 | public int getOffscreenPageLimit() {
249 | return mViewPager2.getOffscreenPageLimit();
250 | }
251 |
252 | public void registerOnPageChangeCallback(@NonNull ViewPager2.OnPageChangeCallback callback) {
253 | mViewPager2.registerOnPageChangeCallback(callback);
254 | }
255 |
256 | public void unregisterOnPageChangeCallback(@NonNull ViewPager2.OnPageChangeCallback callback) {
257 | mViewPager2.unregisterOnPageChangeCallback(callback);
258 | }
259 |
260 | @Override
261 | public boolean canScrollHorizontally(int direction) {
262 | return mViewPager2.canScrollHorizontally(direction);
263 | }
264 |
265 | @Override
266 | public boolean canScrollVertically(int direction) {
267 | return mViewPager2.canScrollVertically(direction);
268 | }
269 |
270 | private static class AttachListener implements OnAttachStateChangeListener {
271 |
272 | WeakReference reference;
273 | View view;
274 |
275 | public AttachListener(ConsecutiveViewPager2 parent, View view) {
276 | reference = new WeakReference(parent);
277 | this.view = view;
278 | }
279 |
280 | @Override
281 | public void onViewAttachedToWindow(View v) {
282 | if (reference.get() != null) {
283 | reference.get().scrollChildContent(view);
284 | }
285 | }
286 |
287 | @Override
288 | public void onViewDetachedFromWindow(View v) {
289 |
290 | }
291 | }
292 | }
293 |
--------------------------------------------------------------------------------
/consecutivescroller/src/main/java/com/donkingliang/consecutivescroller/IConsecutiveScroller.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescroller;
2 |
3 | import android.view.View;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * @Author donkingliang
9 | * @Description ConsecutiveScrollerLayout默认只会处理它的直接子view的滑动事件,
10 | * 为了让ConsecutiveScrollerLayout能支持滑动子view的下级view,提供了IConsecutiveScroller接口。
11 | *
12 | * 子view实现IConsecutiveScroller接口,并通过实现接口方法告诉ConsecutiveScrollerLayout需要滑动的下级view,
13 | * ConsecutiveScrollerLayout就能正确地处理它的滑动事件。
14 | * @Date 2020/4/18
15 | */
16 | public interface IConsecutiveScroller {
17 |
18 | /**
19 | * 返回当前需要滑动的下级view。在一个时间点里只能有一个view可以滑动。
20 | * @return
21 | */
22 | View getCurrentScrollerView();
23 |
24 | /**
25 | * 返回所有可以滑动的子view。由于ConsecutiveScrollerLayout允许它的子view包含多个可滑动的子view,所以返回一个view列表。
26 | * @return
27 | */
28 | List getScrolledViews();
29 | }
30 |
--------------------------------------------------------------------------------
/consecutivescroller/src/main/java/com/donkingliang/consecutivescroller/LayoutParamsUtils.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescroller;
2 |
3 | import android.view.ViewGroup;
4 |
5 | /**
6 | * @Author donkingliang
7 | * @Description
8 | * @Date 2020/5/22
9 | */
10 | public class LayoutParamsUtils {
11 |
12 | /**
13 | * 使子view的topMargin和bottomMargin属性无效
14 | *
15 | * @param params
16 | */
17 | public static void invalidTopAndBottomMargin(ViewGroup.MarginLayoutParams params){
18 | if (params != null) {
19 | params.topMargin = 0;
20 | params.bottomMargin = 0;
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/consecutivescroller/src/main/java/com/donkingliang/consecutivescroller/OverScrollInterpolator.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescroller;
2 |
3 | import android.view.animation.Interpolator;
4 |
5 | /**
6 | * OverScrollInterpolator
7 | * Copy from scwang: SmartUtil.
8 | */
9 | public class OverScrollInterpolator implements Interpolator {
10 |
11 | public static int INTERPOLATOR_VISCOUS_FLUID = 0;
12 | public static int INTERPOLATOR_DECELERATE = 1;
13 |
14 | private int type;
15 |
16 | public OverScrollInterpolator(int type) {
17 | this.type = type;
18 | }
19 |
20 | /**
21 | * Controls the viscous fluid effect (how much of it).
22 | */
23 | private static final float VISCOUS_FLUID_SCALE = 8.0f;
24 |
25 | private static final float VISCOUS_FLUID_NORMALIZE;
26 | private static final float VISCOUS_FLUID_OFFSET;
27 |
28 | static {
29 | // must be set to 1.0 (used in viscousFluid())
30 | VISCOUS_FLUID_NORMALIZE = 1.0f / viscousFluid(1.0f);
31 | // account for very small floating-point error
32 | VISCOUS_FLUID_OFFSET = 1.0f - VISCOUS_FLUID_NORMALIZE * viscousFluid(1.0f);
33 | }
34 |
35 | private static float viscousFluid(float x) {
36 | x *= VISCOUS_FLUID_SCALE;
37 | if (x < 1.0f) {
38 | x -= (1.0f - (float) Math.exp(-x));
39 | } else {
40 | float start = 0.36787944117f; // 1/e == exp(-1)
41 | x = 1.0f - (float) Math.exp(1.0f - x);
42 | x = start + x * (1.0f - start);
43 | }
44 | return x;
45 | }
46 |
47 | @Override
48 | public float getInterpolation(float input) {
49 | if (type == INTERPOLATOR_DECELERATE) {
50 | return (1.0f - (1.0f - input) * (1.0f - input));
51 | }
52 | final float interpolated = VISCOUS_FLUID_NORMALIZE * viscousFluid(input);
53 | if (interpolated > 0) {
54 | return interpolated + VISCOUS_FLUID_OFFSET;
55 | }
56 | return interpolated;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/consecutivescroller/src/main/java/com/donkingliang/consecutivescroller/ScrollUtils.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescroller;
2 |
3 | import android.graphics.Rect;
4 | import android.os.Build;
5 | import android.view.MotionEvent;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.AbsListView;
9 |
10 | import androidx.core.view.ScrollingView;
11 | import androidx.core.view.ViewCompat;
12 | import androidx.recyclerview.widget.LinearLayoutManager;
13 | import androidx.recyclerview.widget.RecyclerView;
14 | import androidx.recyclerview.widget.StaggeredGridLayoutManager;
15 |
16 | import java.lang.reflect.Method;
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | /**
21 | * @Author donkingliang
22 | * @Description
23 | * @Date 2020/3/17
24 | */
25 | public class ScrollUtils {
26 |
27 | static Method computeVerticalScrollOffsetMethod;
28 | static Method computeVerticalScrollRangeMethod;
29 | static Method computeVerticalScrollExtentMethod;
30 |
31 | static int computeVerticalScrollOffset(View view) {
32 | View scrolledView = getScrolledView(view);
33 |
34 | if (scrolledView instanceof ScrollingView) {
35 | return ((ScrollingView) scrolledView).computeVerticalScrollOffset();
36 | }
37 |
38 | try {
39 | if (computeVerticalScrollOffsetMethod == null) {
40 | computeVerticalScrollOffsetMethod = View.class.getDeclaredMethod("computeVerticalScrollOffset");
41 | computeVerticalScrollOffsetMethod.setAccessible(true);
42 | }
43 | Object o = computeVerticalScrollOffsetMethod.invoke(scrolledView);
44 | if (o != null) {
45 | return (int) o;
46 | }
47 | } catch (Exception e) {
48 | e.printStackTrace();
49 | }
50 | return scrolledView.getScrollY();
51 | }
52 |
53 | static int computeVerticalScrollRange(View view) {
54 | View scrolledView = getScrolledView(view);
55 |
56 | if (scrolledView instanceof ScrollingView) {
57 | return ((ScrollingView) scrolledView).computeVerticalScrollRange();
58 | }
59 |
60 | try {
61 | if (computeVerticalScrollRangeMethod == null) {
62 | computeVerticalScrollRangeMethod = View.class.getDeclaredMethod("computeVerticalScrollRange");
63 | computeVerticalScrollRangeMethod.setAccessible(true);
64 | }
65 | Object o = computeVerticalScrollRangeMethod.invoke(scrolledView);
66 | if (o != null) {
67 | return (int) o;
68 | }
69 | } catch (Exception e) {
70 | e.printStackTrace();
71 | }
72 | return scrolledView.getHeight();
73 | }
74 |
75 | static int computeVerticalScrollExtent(View view) {
76 | View scrolledView = getScrolledView(view);
77 |
78 | if (scrolledView instanceof ScrollingView) {
79 | return ((ScrollingView) scrolledView).computeVerticalScrollExtent();
80 | }
81 |
82 | try {
83 | if (computeVerticalScrollExtentMethod == null) {
84 | computeVerticalScrollExtentMethod = View.class.getDeclaredMethod("computeVerticalScrollExtent");
85 | computeVerticalScrollExtentMethod.setAccessible(true);
86 | }
87 |
88 | Object o = computeVerticalScrollExtentMethod.invoke(scrolledView);
89 | if (o != null) {
90 | return (int) o;
91 | }
92 | } catch (Exception e) {
93 | e.printStackTrace();
94 | }
95 | return scrolledView.getHeight();
96 | }
97 |
98 | /**
99 | * 获取View滑动到自身顶部的偏移量
100 | *
101 | * @param view
102 | * @return
103 | */
104 | static int getScrollTopOffset(View view) {
105 | if (isConsecutiveScrollerChild(view) && canScrollVertically(view, -1)) {
106 | return Math.min(-computeVerticalScrollOffset(view), -1);
107 | } else {
108 | return 0;
109 | }
110 | }
111 |
112 | /**
113 | * 获取View滑动到自身底部的偏移量
114 | *
115 | * @param view
116 | * @return
117 | */
118 | static int getScrollBottomOffset(View view) {
119 | if (isConsecutiveScrollerChild(view) && canScrollVertically(view, 1)) {
120 | return Math.max(computeVerticalScrollRange(view) - computeVerticalScrollOffset(view)
121 | - computeVerticalScrollExtent(view), 1);
122 | } else {
123 | return 0;
124 | }
125 | }
126 |
127 | /**
128 | * 是否是可以水平滚动View。(内容可以滚动,或者本身就是个滚动布局)
129 | *
130 | * @param view
131 | * @return
132 | */
133 | static boolean canScrollHorizontally(View view) {
134 | return isConsecutiveScrollerChild(view) && (view.canScrollHorizontally(1) || view.canScrollHorizontally(-1));
135 | }
136 |
137 | /**
138 | * 是否是可以垂直滚动View。(内容可以滚动,或者本身就是个滚动布局)
139 | *
140 | * @param view
141 | * @return
142 | */
143 | static boolean canScrollVertically(View view) {
144 | return isConsecutiveScrollerChild(view) && (canScrollVertically(view, 1) || canScrollVertically(view, -1));
145 | }
146 |
147 | private static final Rect mBounds = new Rect();
148 |
149 | /**
150 | * 判断是否可以滑动
151 | *
152 | * @param view
153 | * @param direction
154 | * @return
155 | */
156 | static boolean canScrollVertically(View view, int direction) {
157 | View scrolledView = getScrolledView(view);
158 |
159 | if (scrolledView.getVisibility() == View.GONE) {
160 | // 隐藏状态,不能滑动
161 | return false;
162 | }
163 |
164 | if (scrolledView instanceof AbsListView) {
165 | AbsListView listView = (AbsListView) scrolledView;
166 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
167 | return listView.canScrollList(direction);
168 | } else {
169 | // 低版本手机(android 19以下),AbsListView不支持滑动
170 | return false;
171 | }
172 | } else {
173 | // RecyclerView通过canScrollVertically方法判断滑动到边界不准确,需要单独处理
174 | if (scrolledView instanceof RecyclerView) {
175 | RecyclerView recyclerView = (RecyclerView) scrolledView;
176 |
177 | if (recyclerView.canScrollHorizontally(1) || recyclerView.canScrollHorizontally(-1)) {
178 | // 如果recyclerView可以水平滑动,并且使用canScrollVertically判断不能垂直滑动,这认定是不能垂直滑动的。
179 | // 这样做既兼顾了recyclerView同时水平、垂直滑动的情况,又保证了垂直滑动的判断是通过自定义的方式判断的。
180 | if (!recyclerView.canScrollVertically(direction)) {
181 | return false;
182 | }
183 | }
184 |
185 | RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
186 | RecyclerView.Adapter adapter = recyclerView.getAdapter();
187 |
188 | if (layoutManager != null && adapter != null && adapter.getItemCount() > 0) {
189 |
190 | boolean isReverseLayout = false;
191 | if (layoutManager instanceof LinearLayoutManager) {
192 | isReverseLayout = ((LinearLayoutManager) layoutManager).getReverseLayout();
193 | } else if (layoutManager instanceof StaggeredGridLayoutManager){
194 | isReverseLayout = ((StaggeredGridLayoutManager) layoutManager).getReverseLayout();
195 | }
196 |
197 | int targetPosition = 0;
198 | if (isReverseLayout) {
199 | targetPosition = direction < 0 ? adapter.getItemCount() - 1 : 0;
200 | } else {
201 | targetPosition = direction > 0 ? adapter.getItemCount() - 1 : 0;
202 | }
203 |
204 | View itemView = layoutManager.findViewByPosition(targetPosition);
205 | if (itemView == null) {
206 | return true;
207 | }
208 | } else {
209 | return false;
210 | }
211 |
212 | int count = recyclerView.getChildCount();
213 | if (direction > 0) {
214 | for (int i = count - 1; i >= 0; i--) {
215 | View child = recyclerView.getChildAt(i);
216 | recyclerView.getDecoratedBoundsWithMargins(child, mBounds);
217 | if (mBounds.bottom > recyclerView.getHeight() - recyclerView.getPaddingBottom()) {
218 | return true;
219 | }
220 | }
221 | return false;
222 | } else {
223 | for (int i = 0; i < count; i++) {
224 | View child = recyclerView.getChildAt(i);
225 | recyclerView.getDecoratedBoundsWithMargins(child, mBounds);
226 | if (mBounds.top < recyclerView.getPaddingTop()) {
227 | return true;
228 | }
229 | }
230 | return false;
231 | }
232 | }
233 |
234 | return scrolledView.canScrollVertically(direction);
235 | }
236 | }
237 |
238 | /**
239 | * 获取当前触摸点下的View
240 | *
241 | * @param rootView
242 | * @param touchX
243 | * @param touchY
244 | * @return
245 | */
246 | static List getTouchViews(View rootView, int touchX, int touchY) {
247 | List views = new ArrayList<>();
248 | addTouchViews(views, rootView, touchX, touchY);
249 | return views;
250 | }
251 |
252 | private static void addTouchViews(List views, View view, int touchX, int touchY) {
253 | if (isConsecutiveScrollerChild(view) && isTouchPointInView(view, touchX, touchY)) {
254 | views.add(view);
255 |
256 | if (view instanceof ViewGroup) {
257 | ViewGroup viewGroup = (ViewGroup) view;
258 | int count = viewGroup.getChildCount();
259 | for (int i = 0; i < count; i++) {
260 | addTouchViews(views, viewGroup.getChildAt(i), touchX, touchY);
261 | }
262 | }
263 | }
264 | }
265 |
266 | /**
267 | * 判断触摸点是否在View内
268 | *
269 | * @param view
270 | * @param x
271 | * @param y
272 | * @return
273 | */
274 | static boolean isTouchPointInView(View view, int x, int y) {
275 | if (view == null) {
276 | return false;
277 | }
278 | int[] position = new int[2];
279 | view.getLocationOnScreen(position);
280 | int left = position[0];
281 | int top = position[1];
282 | int right = left + view.getMeasuredWidth();
283 | int bottom = top + view.getMeasuredHeight();
284 |
285 | if (x >= left && x <= right && y >= top && y <= bottom) {
286 | return true;
287 | }
288 | return false;
289 | }
290 |
291 | static int getRawX(View rootView, MotionEvent ev, int pointerIndex) {
292 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
293 | return (int) ev.getRawX(pointerIndex);
294 | } else {
295 | int[] position = new int[2];
296 | rootView.getLocationOnScreen(position);
297 | int left = position[0];
298 | return (int) (left + ev.getX(pointerIndex));
299 | }
300 | }
301 |
302 | static int getRawY(View rootView, MotionEvent ev, int pointerIndex) {
303 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
304 | return (int) ev.getRawY(pointerIndex);
305 | } else {
306 | int[] position = new int[2];
307 | rootView.getLocationOnScreen(position);
308 | int top = position[1];
309 | return (int) (top + ev.getY(pointerIndex));
310 | }
311 | }
312 |
313 | static List getScrollOffsetForViews(List views) {
314 | List offsets = new ArrayList<>();
315 | for (View view : views) {
316 | offsets.add(computeVerticalScrollOffset(view));
317 | }
318 | return offsets;
319 | }
320 |
321 | static boolean equalsOffsets(List offsets1, List offsets2) {
322 | if (offsets1.size() != offsets2.size()) {
323 | return false;
324 | }
325 |
326 | int size = offsets1.size();
327 |
328 | for (int i = 0; i < size; i++) {
329 | if (!offsets1.get(i).equals(offsets2.get(i))) {
330 | return false;
331 | }
332 | }
333 | return true;
334 | }
335 |
336 | /**
337 | * 判断View是否是支持连续滚动的
338 | *
339 | * @param view
340 | * @return
341 | */
342 | static boolean isConsecutiveScrollerChild(View view) {
343 | if (view != null) {
344 | ViewGroup.LayoutParams lp = view.getLayoutParams();
345 |
346 | if (lp instanceof ConsecutiveScrollerLayout.LayoutParams) {
347 | return ((ConsecutiveScrollerLayout.LayoutParams) lp).isConsecutive;
348 | }
349 | return true;
350 | }
351 | return false;
352 | }
353 |
354 | /**
355 | * 返回需要滑动的view,如果没有,就返回本身。
356 | *
357 | * @param view
358 | * @return
359 | */
360 | static View getScrolledView(View view) {
361 | View consecutiveView = null;
362 |
363 | // 先处理layout_scrollChild指定滑动view的情况
364 | View scrolledView = getScrollChild(view);
365 |
366 | while (scrolledView instanceof IConsecutiveScroller) {
367 | consecutiveView = scrolledView;
368 | scrolledView = ((IConsecutiveScroller) scrolledView).getCurrentScrollerView();
369 |
370 | if (consecutiveView == scrolledView) {
371 | break;
372 | }
373 | }
374 |
375 | return scrolledView;
376 | }
377 |
378 | /**
379 | * 如果通过layout_scrollChild指定的滑动子view,则返回子view,否则返回view
380 | *
381 | * @param view
382 | * @return
383 | */
384 | static View getScrollChild(View view) {
385 | if (view != null) {
386 | ViewGroup.LayoutParams lp = view.getLayoutParams();
387 |
388 | if (lp instanceof ConsecutiveScrollerLayout.LayoutParams) {
389 | int childId = ((ConsecutiveScrollerLayout.LayoutParams) lp).scrollChild;
390 | if (childId != View.NO_ID) {
391 | View child = view.findViewById(childId);
392 | if (child != null) {
393 | return child;
394 | }
395 | }
396 | }
397 | }
398 | return view;
399 | }
400 |
401 | static boolean startInterceptRequestLayout(RecyclerView view) {
402 | if ("InterceptRequestLayout".equals(view.getTag())) {
403 | try {
404 | Method method = RecyclerView.class.getDeclaredMethod("startInterceptRequestLayout");
405 | method.setAccessible(true);
406 | method.invoke(view);
407 | return true;
408 | } catch (Exception e) {
409 | }
410 | }
411 | return false;
412 | }
413 |
414 | static void stopInterceptRequestLayout(RecyclerView view) {
415 | if ("InterceptRequestLayout".equals(view.getTag())) {
416 | try {
417 | Method method = RecyclerView.class.getDeclaredMethod("stopInterceptRequestLayout", boolean.class);
418 | method.setAccessible(true);
419 | method.invoke(view, false);
420 | } catch (Exception e) {
421 | }
422 | }
423 | }
424 |
425 | /**
426 | * 判断父级容器是否是isConsecutive:true.判断到最近的ConsecutiveScrollerLayout容器
427 | *
428 | * @param view
429 | * @return
430 | */
431 | static boolean isConsecutiveScrollParent(View view) {
432 | View child = view;
433 | while (child.getParent() instanceof ViewGroup && !(child.getParent() instanceof ConsecutiveScrollerLayout)) {
434 | child = (View) child.getParent();
435 | }
436 |
437 | if (child.getParent() instanceof ConsecutiveScrollerLayout) {
438 | return isConsecutiveScrollerChild(child);
439 | } else {
440 | return false;
441 | }
442 | }
443 |
444 | /**
445 | * 判断当前触摸点下是否有view可以水平滑动
446 | *
447 | * @param rootView
448 | * @param touchX
449 | * @param touchY
450 | * @return
451 | */
452 | static boolean isHorizontalScroll(View rootView, int touchX, int touchY) {
453 | List views = getTouchViews(rootView, touchX, touchY);
454 | for (View view : views) {
455 | if (view.canScrollHorizontally(1) || view.canScrollHorizontally(-1)) {
456 | return true;
457 | }
458 | }
459 | return false;
460 | }
461 |
462 | /**
463 | * 是否触摸吸顶view并且不能触发布局滑动
464 | *
465 | * @return
466 | */
467 | static boolean isTouchNotTriggerScrollStick(View rootView, int touchX, int touchY) {
468 | List csLayouts = getInTouchCSLayout(rootView, touchX, touchY);
469 | int size = csLayouts.size();
470 | for (int i = size - 1; i >= 0; i--) {
471 | ConsecutiveScrollerLayout csl = csLayouts.get(i);
472 | View topView = getTopViewInTouch(csl, touchX, touchY);
473 | if (topView != null && csl.isStickyView(topView) && csl.theChildIsStick(topView)) {
474 | ConsecutiveScrollerLayout.LayoutParams lp = (ConsecutiveScrollerLayout.LayoutParams) topView.getLayoutParams();
475 | if (!lp.isTriggerScroll) {
476 | return true;
477 | }
478 | }
479 | }
480 | return false;
481 | }
482 |
483 | /**
484 | * 获取触摸点下的所有ConsecutiveScrollerLayout
485 | *
486 | * @param rootView
487 | * @param touchX
488 | * @param touchY
489 | * @return
490 | */
491 | static List getInTouchCSLayout(View rootView, int touchX, int touchY) {
492 | List csLayouts = new ArrayList<>();
493 | List views = getTouchViews(rootView, touchX, touchY);
494 | for (View view : views) {
495 | if (view instanceof ConsecutiveScrollerLayout) {
496 | csLayouts.add((ConsecutiveScrollerLayout) view);
497 | }
498 | }
499 | return csLayouts;
500 | }
501 |
502 | static View getTopViewInTouch(ConsecutiveScrollerLayout csl, int touchX, int touchY) {
503 | int count = csl.getChildCount();
504 | View topTouchView = null;
505 |
506 | for (int i = 0; i < count; i++) {
507 | View child = csl.getChildAt(i);
508 | if (child.getVisibility() == View.VISIBLE && isTouchPointInView(child, touchX, touchY)) {
509 | if (topTouchView == null) {
510 | topTouchView = child;
511 | continue;
512 | }
513 |
514 | if (ViewCompat.getZ(child) > ViewCompat.getZ(topTouchView) // 判断View的Z高度
515 | || (ViewCompat.getZ(child) == ViewCompat.getZ(topTouchView)
516 | && csl.getDrawingPosition(child) > csl.getDrawingPosition(topTouchView))) { // 判断绘制顺序
517 | topTouchView = child;
518 | }
519 | }
520 | }
521 |
522 | return topTouchView;
523 | }
524 | }
525 |
--------------------------------------------------------------------------------
/consecutivescroller/src/main/java/com/donkingliang/consecutivescroller/Util.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescroller;
2 |
3 | import android.content.res.Resources;
4 |
5 | public class Util {
6 |
7 | private static float density = Resources.getSystem().getDisplayMetrics().density;
8 |
9 | /**
10 | * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
11 | * @param dpValue 虚拟像素
12 | * @return 像素
13 | */
14 | public static int dp2px(float dpValue) {
15 | return (int) (0.5f + dpValue * density);
16 | }
17 |
18 | /**
19 | * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
20 | * @param pxValue 像素
21 | * @return 虚拟像素
22 | */
23 | public static float px2dp(int pxValue) {
24 | return (pxValue / density);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/consecutivescroller/src/main/res/values/attrs.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 |
--------------------------------------------------------------------------------
/consecutivescroller/src/test/java/com/donkingliang/consecutivescroller/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.donkingliang.consecutivescroller;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donkingliang/ConsecutiveScroller/bad427106fa54044b22c632d9f3a7a546bd9f7e3/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Jul 31 23:13:54 CST 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/image/permanent_sticky.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donkingliang/ConsecutiveScroller/bad427106fa54044b22c632d9f3a7a546bd9f7e3/image/permanent_sticky.gif
--------------------------------------------------------------------------------
/image/sample.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donkingliang/ConsecutiveScroller/bad427106fa54044b22c632d9f3a7a546bd9f7e3/image/sample.gif
--------------------------------------------------------------------------------
/image/sink_sticky.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donkingliang/ConsecutiveScroller/bad427106fa54044b22c632d9f3a7a546bd9f7e3/image/sink_sticky.gif
--------------------------------------------------------------------------------
/image/sticky.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donkingliang/ConsecutiveScroller/bad427106fa54044b22c632d9f3a7a546bd9f7e3/image/sticky.gif
--------------------------------------------------------------------------------
/image/viewpager.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donkingliang/ConsecutiveScroller/bad427106fa54044b22c632d9f3a7a546bd9f7e3/image/viewpager.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':consecutivescroller'
2 | rootProject.name='ConsecutiveScroller'
3 |
--------------------------------------------------------------------------------