├── .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 | ![sample](https://upload-images.jianshu.io/upload_images/2365010-1d0ebf289428ce8c.gif?imageMogr2/auto-orient/strip) 14 | ![sticky](https://upload-images.jianshu.io/upload_images/2365010-f2b64d20022d2566.gif?imageMogr2/auto-orient/strip) 15 | ![permanent_sticky](https://github.com/donkingliang/ConsecutiveScroller/blob/master/image/permanent_sticky.gif?raw=true) 16 | ![sink_sticky](https://github.com/donkingliang/ConsecutiveScroller/blob/master/image/sink_sticky.gif?raw=true) 17 | ![viewpager](https://github.com/donkingliang/ConsecutiveScroller/blob/master/image/viewpager.gif?raw=true) 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 | Apache-2.0 license 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 mFragments; 18 | 19 | public MyFragmentPagerAdapter(@NonNull FragmentActivity fragmentActivity, List 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 mFragments; 17 | 18 | public TabPagerAdapter(FragmentManager fm, List titleList, List 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 |