├── .github
├── FUNDING.yml
├── ISSUE_TEMPLATE
│ ├── config.yml
│ ├── issue_zh_template_bug.yml
│ ├── issue_zh_template_question.yml
│ └── issue_zh_template_suggest.yml
└── workflows
│ └── android.yml
├── .gitignore
├── LICENSE
├── README.md
├── app
├── AppSignature.jks
├── build.gradle
├── gradle.properties
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── hjq
│ │ └── nested
│ │ └── scroll
│ │ └── demo
│ │ ├── MainActivity.java
│ │ └── fragment
│ │ ├── FrameLayoutFragment.java
│ │ ├── LinearLayoutFragment.java
│ │ ├── RelativeLayoutFragment.java
│ │ └── WebViewFragment.java
│ └── res
│ ├── drawable
│ └── ic_android.png
│ ├── layout
│ ├── activity_main.xml
│ ├── fragment_frame_layout.xml
│ ├── fragment_linear_layout.xml
│ ├── fragment_relative_layout.xml
│ └── fragment_web_view.xml
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-v23
│ └── styles.xml
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── com
│ └── hjq
│ └── nested
│ └── scroll
│ └── layout
│ ├── NestedScrollFrameLayout.java
│ ├── NestedScrollLinearLayout.java
│ ├── NestedScrollRelativeLayout.java
│ ├── NestedScrollViewPager.java
│ └── NestedScrollWebView.java
├── logo.png
├── picture
├── download_demo_apk_qr_code.png
└── dynamic_figure.gif
└── settings.gradle
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: https://raw.githubusercontent.com/getActivity/Donate/master/picture/pay_ali.png
13 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: false
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/issue_zh_template_bug.yml:
--------------------------------------------------------------------------------
1 | name: 提交 Bug
2 | description: 请告诉我框架存在的问题,我会协助你解决此问题!
3 | title: "[Bug]:"
4 | labels: ["bug"]
5 |
6 | body:
7 | - type: markdown
8 | attributes:
9 | value: |
10 | ## [【警告:请务必按照 issue 模板填写,不要抱有侥幸心理,一旦发现 issue 没有按照模板认真填写,一律直接关闭】](https://github.com/getActivity/IssueTemplateGuide)
11 | - type: input
12 | id: input_id_1
13 | attributes:
14 | label: 框架版本【必填】
15 | description: 请输入你使用的框架版本
16 | validations:
17 | required: true
18 | - type: textarea
19 | id: input_id_2
20 | attributes:
21 | label: 问题描述【必填】
22 | description: 请输入你对这个问题的描述
23 | validations:
24 | required: true
25 | - type: textarea
26 | id: input_id_3
27 | attributes:
28 | label: 复现步骤【必填】
29 | description: 请输入问题的复现步骤
30 | validations:
31 | required: true
32 | - type: dropdown
33 | id: input_id_4
34 | attributes:
35 | label: 是否必现【必填】
36 | multiple: false
37 | options:
38 | - 未选择
39 | - 是
40 | - 否
41 | validations:
42 | required: true
43 | - type: input
44 | id: input_id_5
45 | attributes:
46 | label: 项目 targetSdkVersion【必填】
47 | validations:
48 | required: true
49 | - type: input
50 | id: input_id_6
51 | attributes:
52 | label: 出现问题的手机信息【必填】
53 | description: 请填写出现问题的品牌和机型
54 | validations:
55 | required: true
56 | - type: input
57 | id: input_id_7
58 | attributes:
59 | label: 出现问题的安卓版本【必填】
60 | description: 请填写出现问题的 Android 版本
61 | validations:
62 | required: true
63 | - type: dropdown
64 | id: input_id_8
65 | attributes:
66 | label: 问题信息的来源渠道【必填】
67 | multiple: true
68 | options:
69 | - 自己遇到的
70 | - Bugly 看到的
71 | - 用户反馈
72 | - 其他渠道
73 | - type: input
74 | id: input_id_9
75 | attributes:
76 | label: 是部分机型还是所有机型都会出现【必答】
77 | description: 部分/全部(例如:某为,某 Android 版本会出现)
78 | validations:
79 | required: true
80 | - type: dropdown
81 | id: input_id_10
82 | attributes:
83 | label: 框架最新的版本是否存在这个问题【必答】
84 | description: 如果用的是旧版本的话,建议升级看问题是否还存在
85 | multiple: false
86 | options:
87 | - 未选择
88 | - 是
89 | - 否
90 | validations:
91 | required: true
92 | - type: dropdown
93 | id: input_id_11
94 | attributes:
95 | label: 框架文档是否提及了该问题【必答】
96 | description: 文档会提供最常见的问题解答,可以先看看是否有自己想要的
97 | multiple: false
98 | options:
99 | - 未选择
100 | - 是
101 | - 否
102 | validations:
103 | required: true
104 | - type: dropdown
105 | id: input_id_12
106 | attributes:
107 | label: 是否已经查阅框架文档但还未能解决的【必答】
108 | description: 如果查阅了文档但还是没有解决的话,可以选择是
109 | multiple: false
110 | options:
111 | - 未选择
112 | - 是
113 | - 否
114 | validations:
115 | required: true
116 | - type: dropdown
117 | id: input_id_13
118 | attributes:
119 | label: issue 列表中是否有人曾提过类似的问题【必答】
120 | description: 可以在 issue 列表在搜索问题关键字,参考一下别人的解决方案
121 | multiple: false
122 | options:
123 | - 未选择
124 | - 是
125 | - 否
126 | validations:
127 | required: true
128 | - type: dropdown
129 | id: input_id_14
130 | attributes:
131 | label: 是否已经搜索过了 issue 列表但还未能解决的【必答】
132 | description: 如果搜索过了 issue 列表但是问题没有解决的话,可以选择是
133 | multiple: false
134 | options:
135 | - 未选择
136 | - 是
137 | - 否
138 | validations:
139 | required: true
140 | - type: dropdown
141 | id: input_id_15
142 | attributes:
143 | label: 是否可以通过 Demo 来复现该问题【必答】
144 | description: 排查一下是不是自己的项目代码写得有问题导致的
145 | multiple: false
146 | options:
147 | - 未选择
148 | - 是
149 | - 否
150 | validations:
151 | required: true
152 | - type: textarea
153 | id: input_id_16
154 | attributes:
155 | label: 提供报错堆栈
156 | description: 如果有报错的话必填,注意不要拿被混淆过的代码堆栈上来
157 | render: text
158 | validations:
159 | required: false
160 | - type: textarea
161 | id: input_id_17
162 | attributes:
163 | label: 提供截图或视频
164 | description: 根据需要提供,此项不强制
165 | validations:
166 | required: false
167 | - type: textarea
168 | id: input_id_18
169 | attributes:
170 | label: 提供解决方案
171 | description: 如果已经解决了的话,此项不强制
172 | validations:
173 | required: false
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/issue_zh_template_question.yml:
--------------------------------------------------------------------------------
1 | name: 提出疑问
2 | description: 提出你的困惑,我会给你解答
3 | title: "[疑惑]:"
4 | labels: ["question"]
5 |
6 | body:
7 | - type: markdown
8 | attributes:
9 | value: |
10 | ## [【警告:请务必按照 issue 模板填写,不要抱有侥幸心理,一旦发现 issue 没有按照模板认真填写,一律直接关闭】](https://github.com/getActivity/IssueTemplateGuide)
11 | - type: textarea
12 | id: input_id_1
13 | attributes:
14 | label: 问题描述【必填】
15 | description: 请描述一下你的问题(注意:如果确定是框架 bug 请不要在这里提,否则一概不受理)
16 | validations:
17 | required: true
18 | - type: dropdown
19 | id: input_id_2
20 | attributes:
21 | label: 框架文档是否提及了该问题【必答】
22 | description: 文档会提供最常见的问题解答,可以先看看是否有自己想要的
23 | multiple: false
24 | options:
25 | - 未选择
26 | - 是
27 | - 否
28 | validations:
29 | required: true
30 | - type: dropdown
31 | id: input_id_3
32 | attributes:
33 | label: 是否已经查阅框架文档但还未能解决的【必答】
34 | description: 如果查阅了文档但还是没有解决的话,可以选择是
35 | multiple: false
36 | options:
37 | - 未选择
38 | - 是
39 | - 否
40 | validations:
41 | required: true
42 | - type: dropdown
43 | id: input_id_4
44 | attributes:
45 | label: issue 列表中是否有人曾提过类似的问题【必答】
46 | description: 可以在 issue 列表在搜索问题关键字,参考一下别人的解决方案
47 | multiple: false
48 | options:
49 | - 未选择
50 | - 是
51 | - 否
52 | validations:
53 | required: true
54 | - type: dropdown
55 | id: input_id_5
56 | attributes:
57 | label: 是否已经搜索过了 issue 列表但还未能解决的【必答】
58 | description: 如果搜索过了 issue 列表但是问题没有解决的话,可以选择是
59 | multiple: false
60 | options:
61 | - 未选择
62 | - 是
63 | - 否
64 | validations:
65 | required: true
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/issue_zh_template_suggest.yml:
--------------------------------------------------------------------------------
1 | name: 提交建议
2 | description: 请告诉我框架的不足之处,让我做得更好!
3 | title: "[建议]:"
4 | labels: ["help wanted"]
5 |
6 | body:
7 | - type: markdown
8 | attributes:
9 | value: |
10 | ## [【警告:请务必按照 issue 模板填写,不要抱有侥幸心理,一旦发现 issue 没有按照模板认真填写,一律直接关闭】](https://github.com/getActivity/IssueTemplateGuide)
11 | - type: textarea
12 | id: input_id_1
13 | attributes:
14 | label: 你觉得框架有什么不足之处?【必答】
15 | description: 你可以描述框架有什么令你不满意的地方
16 | validations:
17 | required: true
18 | - type: dropdown
19 | id: input_id_2
20 | attributes:
21 | label: issue 是否有人曾提过类似的建议?【必答】
22 | description: 一旦出现重复提问我将不会再次解答
23 | multiple: false
24 | options:
25 | - 未选择
26 | - 是
27 | - 否
28 | validations:
29 | required: true
30 | - type: dropdown
31 | id: input_id_3
32 | attributes:
33 | label: 框架文档是否提及了该问题【必答】
34 | description: 文档会提供最常见的问题解答,可以先看看是否有自己想要的
35 | multiple: false
36 | options:
37 | - 未选择
38 | - 是
39 | - 否
40 | validations:
41 | required: true
42 | - type: dropdown
43 | id: input_id_4
44 | attributes:
45 | label: 是否已经查阅框架文档但还未能解决的【必答】
46 | description: 如果查阅了文档但还是没有解决的话,可以选择是
47 | multiple: false
48 | options:
49 | - 未选择
50 | - 是
51 | - 否
52 | validations:
53 | required: true
54 | - type: textarea
55 | id: input_id_5
56 | attributes:
57 | label: 你觉得该怎么去完善会比较好?【非必答】
58 | description: 你可以提供一下自己的想法或者做法供作者参考
59 | validations:
60 | required: false
--------------------------------------------------------------------------------
/.github/workflows/android.yml:
--------------------------------------------------------------------------------
1 | name: Android CI
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 |
8 | runs-on: ubuntu-latest
9 |
10 | steps:
11 | - uses: actions/checkout@v2
12 | - name: set up JDK 1.8
13 | uses: actions/setup-java@v1
14 | with:
15 | java-version: 1.8
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | .idea
3 | .cxx
4 | .externalNativeBuild
5 | build
6 | captures
7 |
8 | ._*
9 | *.iml
10 | .DS_Store
11 | local.properties
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, October 2021
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright 2021 Huang JinQun
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 嵌套滚动布局
2 |
3 | * 项目地址:[Github](https://github.com/getActivity/NestedScrollLayout)
4 |
5 | * 可以扫码下载 Demo 进行演示或者测试,如果扫码下载不了的,[点击此处可直接下载](https://github.com/getActivity/NestedScrollLayout/releases/download/2.0/NestedScrollLayout.apk)
6 |
7 | 
8 |
9 | * 众所周知,WebView、LinearLayout、FrameLayout、RelativeLayout 是不支持 NestedScroll(嵌套滚动)特性的,于是就有了这个库,专门解决这一问题
10 |
11 | 
12 |
13 | #### 集成步骤
14 |
15 | * 如果你的项目 Gradle 配置是在 `7.0` 以下,需要在 `build.gradle` 文件中加入
16 |
17 | ```groovy
18 | allprojects {
19 | repositories {
20 | // JitPack 远程仓库:https://jitpack.io
21 | maven { url 'https://jitpack.io' }
22 | }
23 | }
24 | ```
25 |
26 | * 如果你的 Gradle 配置是 `7.0` 及以上,则需要在 `settings.gradle` 文件中加入
27 |
28 | ```groovy
29 | dependencyResolutionManagement {
30 | repositories {
31 | // JitPack 远程仓库:https://jitpack.io
32 | maven { url 'https://jitpack.io' }
33 | }
34 | }
35 | ```
36 |
37 | * 配置完远程仓库后,在项目 app 模块下的 `build.gradle` 文件中加入远程依赖
38 |
39 | ```groovy
40 | android {
41 | // 支持 JDK 1.8 及以上
42 | compileOptions {
43 | targetCompatibility JavaVersion.VERSION_1_8
44 | sourceCompatibility JavaVersion.VERSION_1_8
45 | }
46 | }
47 |
48 | dependencies {
49 | // 嵌套滚动布局:https://github.com/getActivity/NestedScrollLayout
50 | implementation 'com.github.getActivity:NestedScrollLayout:2.0'
51 | }
52 | ```
53 |
54 | #### AndroidX 兼容
55 |
56 | * 如果项目是基于 **AndroidX** 包,请在项目 `gradle.properties` 文件中加入
57 |
58 | ```text
59 | # 表示将第三方库迁移到 AndroidX
60 | android.enableJetifier = true
61 | ```
62 |
63 | * 如果项目是基于 **Support** 包则不需要加入此配置
64 |
65 | #### 框架用法
66 |
67 | * NestedScrollWebView
68 |
69 | ```xml
70 |
74 | ```
75 |
76 | * NestedScrollFrameLayout
77 |
78 | ```xml
79 |
82 |
83 |
84 | ```
85 |
86 | * NestedScrollLinearLayout
87 |
88 | ```xml
89 |
90 |
94 |
95 |
96 | ```
97 |
98 | * NestedScrollRelativeLayout
99 |
100 | ```xml
101 |
102 |
105 |
106 |
107 | ```
108 |
109 | * NestedScrollViewPager
110 |
111 | ```xml
112 |
116 | ```
117 |
118 | #### 开源项目列表
119 |
120 | * 安卓技术中台:[AndroidProject](https://github.com/getActivity/AndroidProject)  
121 |
122 | * 安卓技术中台 Kt 版:[AndroidProject-Kotlin](https://github.com/getActivity/AndroidProject-Kotlin)  
123 |
124 | * 权限框架:[XXPermissions](https://github.com/getActivity/XXPermissions)  
125 |
126 | * 吐司框架:[Toaster](https://github.com/getActivity/Toaster)  
127 |
128 | * 网络框架:[EasyHttp](https://github.com/getActivity/EasyHttp)  
129 |
130 | * 标题栏框架:[TitleBar](https://github.com/getActivity/TitleBar)  
131 |
132 | * 悬浮窗框架:[EasyWindow](https://github.com/getActivity/EasyWindow)  
133 |
134 | * Shape 框架:[ShapeView](https://github.com/getActivity/ShapeView)  
135 |
136 | * 语种切换框架:[MultiLanguages](https://github.com/getActivity/MultiLanguages)  
137 |
138 | * Gson 解析容错:[GsonFactory](https://github.com/getActivity/GsonFactory)  
139 |
140 | * 日志查看框架:[Logcat](https://github.com/getActivity/Logcat)  
141 |
142 | * Android 版本适配:[AndroidVersionAdapter](https://github.com/getActivity/AndroidVersionAdapter)  
143 |
144 | * Android 代码规范:[AndroidCodeStandard](https://github.com/getActivity/AndroidCodeStandard)  
145 |
146 | * Android 资源大汇总:[AndroidIndex](https://github.com/getActivity/AndroidIndex)  
147 |
148 | * Android 开源排行榜:[AndroidGithubBoss](https://github.com/getActivity/AndroidGithubBoss)  
149 |
150 | * Studio 精品插件:[StudioPlugins](https://github.com/getActivity/StudioPlugins)  
151 |
152 | * 表情包大集合:[EmojiPackage](https://github.com/getActivity/EmojiPackage)  
153 |
154 | * AI 资源大汇总:[AiIndex](https://github.com/getActivity/AiIndex)  
155 |
156 | * 省市区 Json 数据:[ProvinceJson](https://github.com/getActivity/ProvinceJson)  
157 |
158 | * Markdown 语法文档:[MarkdownDoc](https://github.com/getActivity/MarkdownDoc)  
159 |
160 | #### 微信公众号:Android轮子哥
161 |
162 | 
163 |
164 | #### Android 技术 Q 群:10047167
165 |
166 | #### 如果您觉得我的开源库帮你节省了大量的开发时间,请扫描下方的二维码随意打赏,要是能打赏个 10.24 :monkey_face:就太:thumbsup:了。您的支持将鼓励我继续创作:octocat:([点击查看捐赠列表](https://github.com/getActivity/Donate))
167 |
168 |  
169 |
170 | #### 广告区
171 |
172 | * 我现在任腾讯云服务器推广大使,大家如果有购买服务器的需求,可以通过下面的链接购买
173 |
174 | [](https://curl.qcloud.com/A6cYskvv)
175 |
176 | [【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中](https://curl.qcloud.com/A6cYskvv)
177 |
178 | [](https://curl.qcloud.com/up4fQsdn)
179 |
180 | [【腾讯云】中小企业福利专场,多款刚需产品,满足企业通用场景需求](https://curl.qcloud.com/up4fQsdn)
181 |
182 | ## License
183 |
184 | ```text
185 | Copyright 2018 Huang JinQun
186 |
187 | Licensed under the Apache License, Version 2.0 (the "License");
188 | you may not use this file except in compliance with the License.
189 | You may obtain a copy of the License at
190 |
191 | http://www.apache.org/licenses/LICENSE-2.0
192 |
193 | Unless required by applicable law or agreed to in writing, software
194 | distributed under the License is distributed on an "AS IS" BASIS,
195 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
196 | See the License for the specific language governing permissions and
197 | limitations under the License.
198 | ```
--------------------------------------------------------------------------------
/app/AppSignature.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/getActivity/NestedScrollLayout/ecff3891e04f31be080f5446d6610c1116ff6315/app/AppSignature.jks
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 | defaultConfig {
7 | applicationId "com.hjq.nested.scroll.demo"
8 | minSdkVersion 21
9 | targetSdkVersion 28
10 | versionCode 20
11 | versionName "2.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 |
15 | // Apk 签名的那些事:https://www.jianshu.com/p/a1f8e5896aa2
16 | signingConfigs {
17 | config {
18 | storeFile file(StoreFile)
19 | storePassword StorePassword
20 | keyAlias KeyAlias
21 | keyPassword KeyPassword
22 | }
23 | }
24 |
25 | buildTypes {
26 | debug {
27 | minifyEnabled false
28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
29 | signingConfig signingConfigs.config
30 | }
31 |
32 | release {
33 | minifyEnabled true
34 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
35 | signingConfig signingConfigs.config
36 | }
37 | }
38 |
39 | applicationVariants.all { variant ->
40 | // apk 输出文件名配置
41 | variant.outputs.all { output ->
42 | outputFileName = rootProject.getName() + '.apk'
43 | }
44 | }
45 | }
46 |
47 | dependencies {
48 | // 依赖 libs 目录下所有的 jar 和 aar 包
49 | implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
50 |
51 | implementation project(':library')
52 |
53 | implementation 'com.android.support:appcompat-v7:28.0.0'
54 | implementation 'com.android.support:design:28.0.0'
55 |
56 | // 底部导航栏:https://github.com/aurelhubert/ahbottomnavigation
57 | implementation 'com.aurelhubert:ahbottomnavigation:2.2.0'
58 | }
--------------------------------------------------------------------------------
/app/gradle.properties:
--------------------------------------------------------------------------------
1 | StoreFile = AppSignature.jks
2 | StorePassword = AndroidProject
3 | KeyAlias = AndroidProject
4 | KeyPassword = AndroidProject
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\SDK\Studio\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hjq/nested/scroll/demo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.hjq.nested.scroll.demo;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.support.v4.app.FragmentPagerAdapter;
6 | import android.support.v4.view.ViewPager;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.Toolbar;
9 |
10 | import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
11 | import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
12 | import com.hjq.nested.scroll.demo.fragment.FrameLayoutFragment;
13 | import com.hjq.nested.scroll.demo.fragment.LinearLayoutFragment;
14 | import com.hjq.nested.scroll.demo.fragment.RelativeLayoutFragment;
15 | import com.hjq.nested.scroll.demo.fragment.WebViewFragment;
16 | import com.hjq.nested.scroll.layout.NestedScrollFrameLayout;
17 | import com.hjq.nested.scroll.layout.NestedScrollLinearLayout;
18 | import com.hjq.nested.scroll.layout.NestedScrollRelativeLayout;
19 | import com.hjq.nested.scroll.layout.NestedScrollWebView;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | public class MainActivity extends AppCompatActivity {
25 |
26 | private Toolbar mToolbar;
27 | private AHBottomNavigation mBottomNavigationView;
28 | private ViewPager mViewPager;
29 |
30 | private final List mFragmentSet = new ArrayList<>();
31 | private final List mFragmentTitleSet = new ArrayList<>();
32 |
33 | @Override
34 | protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.activity_main);
37 |
38 | mToolbar = findViewById(R.id.tb_main_toolbar);
39 | mViewPager = findViewById(R.id.ahb_main_pager);
40 | mBottomNavigationView = findViewById(R.id.ahb_main_navigation);
41 |
42 | mBottomNavigationView.addItem(new AHBottomNavigationItem("WebView", R.drawable.ic_android));
43 | mBottomNavigationView.addItem(new AHBottomNavigationItem("LinearLayout", R.drawable.ic_android));
44 | mBottomNavigationView.addItem(new AHBottomNavigationItem("FrameLayout", R.drawable.ic_android));
45 | mBottomNavigationView.addItem(new AHBottomNavigationItem("RelativeLayout", R.drawable.ic_android));
46 |
47 | mFragmentSet.add(new WebViewFragment());
48 | mFragmentTitleSet.add(NestedScrollWebView.class.getSimpleName());
49 | mFragmentSet.add(new LinearLayoutFragment());
50 | mFragmentTitleSet.add(NestedScrollLinearLayout.class.getSimpleName());
51 | mFragmentSet.add(new FrameLayoutFragment());
52 | mFragmentTitleSet.add(NestedScrollFrameLayout.class.getSimpleName());
53 | mFragmentSet.add(new RelativeLayoutFragment());
54 | mFragmentTitleSet.add(NestedScrollRelativeLayout.class.getSimpleName());
55 |
56 | mViewPager.setOffscreenPageLimit(mFragmentSet.size());
57 | mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
58 | @Override
59 | public Fragment getItem(int position) {
60 | return mFragmentSet.get(position);
61 | }
62 |
63 | @Override
64 | public int getCount() {
65 | return mFragmentSet.size();
66 | }
67 | });
68 |
69 | mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
70 |
71 | @Override
72 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
73 |
74 | @Override
75 | public void onPageSelected(int position) {
76 | mBottomNavigationView.setCurrentItem(position, false);
77 | mToolbar.setTitle(mFragmentTitleSet.get(position));
78 | }
79 |
80 | @Override
81 | public void onPageScrollStateChanged(int state) {}
82 | });
83 |
84 | mBottomNavigationView.setOnTabSelectedListener(new AHBottomNavigation.OnTabSelectedListener() {
85 | @Override
86 | public boolean onTabSelected(int position, boolean wasSelected) {
87 | mViewPager.setCurrentItem(position);
88 | return true;
89 | }
90 | });
91 | }
92 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/hjq/nested/scroll/demo/fragment/FrameLayoutFragment.java:
--------------------------------------------------------------------------------
1 | package com.hjq.nested.scroll.demo.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import com.hjq.nested.scroll.demo.R;
12 |
13 | public class FrameLayoutFragment extends Fragment {
14 |
15 | @Nullable
16 | @Override
17 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
18 | return inflater.inflate(R.layout.fragment_frame_layout, container, false);
19 | }
20 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/hjq/nested/scroll/demo/fragment/LinearLayoutFragment.java:
--------------------------------------------------------------------------------
1 | package com.hjq.nested.scroll.demo.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import com.hjq.nested.scroll.demo.R;
12 |
13 | public class LinearLayoutFragment extends Fragment {
14 |
15 | @Nullable
16 | @Override
17 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
18 | return inflater.inflate(R.layout.fragment_linear_layout, container, false);
19 | }
20 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/hjq/nested/scroll/demo/fragment/RelativeLayoutFragment.java:
--------------------------------------------------------------------------------
1 | package com.hjq.nested.scroll.demo.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import com.hjq.nested.scroll.demo.R;
12 |
13 | public class RelativeLayoutFragment extends Fragment {
14 |
15 | @Nullable
16 | @Override
17 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
18 | return inflater.inflate(R.layout.fragment_relative_layout, container, false);
19 | }
20 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/hjq/nested/scroll/demo/fragment/WebViewFragment.java:
--------------------------------------------------------------------------------
1 | package com.hjq.nested.scroll.demo.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.webkit.WebViewClient;
11 |
12 | import com.hjq.nested.scroll.demo.R;
13 | import com.hjq.nested.scroll.layout.NestedScrollWebView;
14 |
15 | public class WebViewFragment extends Fragment {
16 |
17 | @Nullable
18 | @Override
19 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
20 | NestedScrollWebView nestedScrollWebView = (NestedScrollWebView) inflater.inflate(R.layout.fragment_web_view, container, false);
21 | nestedScrollWebView.setWebViewClient(new WebViewClient());
22 | nestedScrollWebView.loadUrl("https://github.com/getActivity");
23 | return nestedScrollWebView;
24 | }
25 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_android.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/getActivity/NestedScrollLayout/ecff3891e04f31be080f5446d6610c1116ff6315/app/src/main/res/drawable/ic_android.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
22 |
23 |
24 |
25 |
30 |
31 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_frame_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_linear_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_relative_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_web_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/getActivity/NestedScrollLayout/ecff3891e04f31be080f5446d6610c1116ff6315/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/getActivity/NestedScrollLayout/ecff3891e04f31be080f5446d6610c1116ff6315/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/getActivity/NestedScrollLayout/ecff3891e04f31be080f5446d6610c1116ff6315/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-v23/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #896961
4 | #896961
5 | #FF0033
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | NestedScrollLayout
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
14 |
15 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | // 阿里云云效仓库:https://maven.aliyun.com/mvn/guide
4 | maven { url 'https://maven.aliyun.com/repository/public' }
5 | maven { url 'https://maven.aliyun.com/repository/google' }
6 | // 华为开源镜像:https://mirrors.huaweicloud.com/
7 | maven { url 'https://repo.huaweicloud.com/repository/maven/' }
8 | // JitPack 远程仓库:https://jitpack.io
9 | maven { url 'https://jitpack.io' }
10 | mavenCentral()
11 | google()
12 | // noinspection JcenterRepositoryObsolete
13 | jcenter()
14 | }
15 | dependencies {
16 | classpath 'com.android.tools.build:gradle:4.1.2'
17 | }
18 | }
19 |
20 | allprojects {
21 | repositories {
22 | maven { url 'https://maven.aliyun.com/repository/public' }
23 | maven { url 'https://maven.aliyun.com/repository/google' }
24 | maven { url 'https://repo.huaweicloud.com/repository/maven/' }
25 | maven { url 'https://jitpack.io' }
26 | mavenCentral()
27 | google()
28 | // noinspection JcenterRepositoryObsolete
29 | jcenter()
30 | }
31 |
32 | // 将构建文件统一输出到项目根目录下的 build 文件夹
33 | setBuildDir(new File(rootDir, "build/${path.replaceAll(':', '/')}"))
34 | }
35 |
36 | task clean(type: Delete) {
37 | delete rootProject.buildDir
38 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
19 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/getActivity/NestedScrollLayout/ecff3891e04f31be080f5446d6610c1116ff6315/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | zipStoreBase = GRADLE_USER_HOME
2 | zipStorePath = wrapper/dists
3 | distributionBase = GRADLE_USER_HOME
4 | distributionPath = wrapper/dists
5 | distributionUrl = https\://services.gradle.org/distributions/gradle-6.5-all.zip
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 26
5 |
6 | defaultConfig {
7 | minSdkVersion 21
8 | versionCode 20
9 | versionName "2.0"
10 | }
11 |
12 | android.libraryVariants.all { variant ->
13 | // aar 输出文件名配置
14 | variant.outputs.all { output ->
15 | outputFileName = "${rootProject.name}-${android.defaultConfig.versionName}.aar"
16 | }
17 | }
18 | }
19 |
20 | dependencies {
21 | // noinspection GradleCompatible
22 | implementation 'com.android.support:appcompat-v7:28.0.0'
23 | }
24 |
25 | afterEvaluate {
26 | // 排除 BuildConfig.class 和 R.class
27 | generateReleaseBuildConfig.enabled = false
28 | generateDebugBuildConfig.enabled = false
29 | generateReleaseResValues.enabled = false
30 | generateDebugResValues.enabled = false
31 | }
32 |
33 | // 防止编码问题
34 | tasks.withType(Javadoc) {
35 | options.addStringOption('Xdoclint:none', '-quiet')
36 | options.addStringOption('encoding', 'UTF-8')
37 | options.addStringOption('charSet', 'UTF-8')
38 | }
39 |
40 | task sourcesJar(type: Jar) {
41 | from android.sourceSets.main.java.srcDirs
42 | classifier = 'sources'
43 | }
44 |
45 | task javadoc(type: Javadoc) {
46 | source = android.sourceSets.main.java.srcDirs
47 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
48 | }
49 |
50 | task javadocJar(type: Jar, dependsOn: javadoc) {
51 | classifier = 'javadoc'
52 | from javadoc.destinationDir
53 | }
54 |
55 | artifacts {
56 | archives javadocJar
57 | archives sourcesJar
58 | }
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/library/src/main/java/com/hjq/nested/scroll/layout/NestedScrollFrameLayout.java:
--------------------------------------------------------------------------------
1 | package com.hjq.nested.scroll.layout;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.support.annotation.NonNull;
6 | import android.support.v4.view.NestedScrollingChild;
7 | import android.support.v4.view.NestedScrollingChildHelper;
8 | import android.support.v4.view.NestedScrollingParent;
9 | import android.support.v4.view.NestedScrollingParentHelper;
10 | import android.support.v4.view.ViewCompat;
11 | import android.util.AttributeSet;
12 | import android.view.MotionEvent;
13 | import android.view.VelocityTracker;
14 | import android.view.View;
15 | import android.view.ViewConfiguration;
16 | import android.view.ViewParent;
17 | import android.widget.FrameLayout;
18 |
19 | /**
20 | * author : Android 轮子哥
21 | * github : https://github.com/getActivity/NestedScrollLayout
22 | * time : 2023/07/02
23 | * desc : 支持嵌套滚动的 FrameLayout
24 | */
25 | public class NestedScrollFrameLayout extends FrameLayout implements NestedScrollingChild, NestedScrollingParent {
26 |
27 | private static final int INVALID_POINTER = -1;
28 |
29 | private final NestedScrollingChildHelper mChildHelper;
30 | private final NestedScrollingParentHelper mParentHelper;
31 |
32 | private final int[] mScrollConsumed = new int[2];
33 | private final int[] mScrollOffset = new int[2];
34 |
35 | private final float mTouchSlop;
36 | private final float mMaximumVelocity;
37 | private final float mMinimumVelocity;
38 |
39 | private int mLastMotionY;
40 | private int mActivePointerId;
41 |
42 | private VelocityTracker mVelocityTracker;
43 |
44 | private boolean mBeingDragged;
45 |
46 | public NestedScrollFrameLayout(Context context) {
47 | this(context, null, 0);
48 | }
49 |
50 | public NestedScrollFrameLayout(Context context, AttributeSet attrs) {
51 | this(context, attrs, 0);
52 | }
53 |
54 | public NestedScrollFrameLayout(Context context, AttributeSet attrs, int defStyle) {
55 | super(context, attrs, defStyle);
56 | setWillNotDraw(false);
57 | mChildHelper = new NestedScrollingChildHelper(this);
58 | mParentHelper = new NestedScrollingParentHelper(this);
59 | setNestedScrollingEnabled(true);
60 | mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
61 | mMaximumVelocity = ViewConfiguration.get(getContext()).getScaledMaximumFlingVelocity();
62 | mMinimumVelocity = ViewConfiguration.get(getContext()).getScaledMinimumFlingVelocity();
63 | }
64 |
65 | @SuppressLint("ClickableViewAccessibility")
66 | @Override
67 | public boolean onTouchEvent(MotionEvent ev) {
68 | MotionEvent event = MotionEvent.obtain(ev);
69 | initVelocityTrackerIfNotExists();
70 | final int actionMasked = event.getActionMasked();
71 |
72 | switch (actionMasked) {
73 | case MotionEvent.ACTION_DOWN: {
74 | mVelocityTracker.addMovement(ev);
75 |
76 | mLastMotionY = (int) event.getY();
77 | mActivePointerId = event.getPointerId(0);
78 | startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
79 | break;
80 | }
81 | case MotionEvent.ACTION_MOVE:
82 | final int activePointerIndex = event.findPointerIndex(mActivePointerId);
83 | if (activePointerIndex == -1) {
84 | break;
85 | }
86 |
87 | final int y = (int) event.getY(activePointerIndex);
88 | int deltaY = mLastMotionY - y;
89 |
90 | if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
91 | deltaY -= mScrollConsumed[1];
92 | event.offsetLocation(0, mScrollOffset[1]);
93 | }
94 | if (!mBeingDragged && Math.abs(mLastMotionY - y) > mTouchSlop) {
95 | final ViewParent parent = getParent();
96 | if (parent != null) {
97 | parent.requestDisallowInterceptTouchEvent(true);
98 | }
99 | mBeingDragged = true;
100 | if (deltaY > 0) {
101 | deltaY -= mTouchSlop;
102 | } else {
103 | deltaY += mTouchSlop;
104 | }
105 | }
106 |
107 | if (mBeingDragged) {
108 | mVelocityTracker.addMovement(ev);
109 |
110 | mLastMotionY = y - mScrollOffset[1];
111 | if (dispatchNestedScroll(0, 0, 0, deltaY, mScrollOffset)) {
112 | mLastMotionY -= mScrollOffset[1];
113 | event.offsetLocation(0, mScrollOffset[1]);
114 | }
115 | }
116 | break;
117 | case MotionEvent.ACTION_CANCEL:
118 | case MotionEvent.ACTION_UP:
119 | if (mBeingDragged) {
120 | mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
121 | int initialVelocity = (int) mVelocityTracker.getYVelocity(mActivePointerId);
122 |
123 | if (Math.abs(initialVelocity) > mMinimumVelocity) {
124 | flingWithNestedDispatch(-initialVelocity) ;
125 | }
126 | }
127 | mActivePointerId = INVALID_POINTER;
128 | endDrag();
129 | break;
130 | case MotionEvent.ACTION_POINTER_DOWN: {
131 | final int index = event.getActionIndex();
132 | mLastMotionY = (int) event.getY(index);
133 | mActivePointerId = event.getPointerId(index);
134 | break;
135 | }
136 | case MotionEvent.ACTION_POINTER_UP:
137 | onSecondaryPointerUp(event);
138 | mLastMotionY = (int) event.getY(event.findPointerIndex(mActivePointerId));
139 | break;
140 | default:
141 | break;
142 | }
143 |
144 | event.recycle();
145 | return true;
146 | }
147 |
148 | private void onSecondaryPointerUp(MotionEvent ev) {
149 | final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
150 | >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
151 | final int pointerId = ev.getPointerId(pointerIndex);
152 | if (pointerId == mActivePointerId) {
153 | final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
154 | mLastMotionY = (int) ev.getY(newPointerIndex);
155 | mActivePointerId = ev.getPointerId(newPointerIndex);
156 | if (mVelocityTracker != null) {
157 | mVelocityTracker.clear();
158 | }
159 | }
160 | }
161 |
162 | private void endDrag() {
163 | mBeingDragged = false;
164 | recycleVelocityTracker();
165 | stopNestedScroll();
166 | }
167 |
168 | private void flingWithNestedDispatch(int velocityY) {
169 | if (!dispatchNestedPreFling(0, velocityY)) {
170 | dispatchNestedFling(0, velocityY, true);
171 | }
172 | }
173 |
174 | private void initVelocityTrackerIfNotExists() {
175 | if (mVelocityTracker == null) {
176 | mVelocityTracker = VelocityTracker.obtain();
177 | }
178 | }
179 |
180 | private void recycleVelocityTracker() {
181 | if (mVelocityTracker != null) {
182 | mVelocityTracker.recycle();
183 | mVelocityTracker = null;
184 | }
185 | }
186 |
187 | @Override
188 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
189 | if (disallowIntercept) {
190 | recycleVelocityTracker();
191 | }
192 | super.requestDisallowInterceptTouchEvent(disallowIntercept);
193 | }
194 |
195 | // NestedScrollingChild
196 |
197 | @Override
198 | public void setNestedScrollingEnabled(boolean enabled) {
199 | mChildHelper.setNestedScrollingEnabled(enabled);
200 | }
201 |
202 | @Override
203 | public boolean isNestedScrollingEnabled() {
204 | return mChildHelper.isNestedScrollingEnabled();
205 | }
206 |
207 | @Override
208 | public boolean startNestedScroll(int axes) {
209 | return mChildHelper.startNestedScroll(axes);
210 | }
211 |
212 | @Override
213 | public void stopNestedScroll() {
214 | mChildHelper.stopNestedScroll();
215 | }
216 |
217 | @Override
218 | public boolean hasNestedScrollingParent() {
219 | return mChildHelper.hasNestedScrollingParent();
220 | }
221 |
222 | @Override
223 | public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow) {
224 | return mChildHelper.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, offsetInWindow);
225 | }
226 |
227 | @Override
228 | public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow) {
229 | return mChildHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow);
230 | }
231 |
232 | @Override
233 | public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed) {
234 | return mChildHelper.dispatchNestedFling(velocityX, velocityY, consumed);
235 | }
236 |
237 | @Override
238 | public boolean dispatchNestedPreFling(float velocityX, float velocityY) {
239 | return mChildHelper.dispatchNestedPreFling(velocityX, velocityY);
240 | }
241 |
242 | // NestedScrollingParent
243 |
244 | @Override
245 | public boolean onStartNestedScroll(@NonNull View child, @NonNull View target, int nestedScrollAxes) {
246 | return (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0;
247 | }
248 |
249 | @Override
250 | public void onNestedScrollAccepted(@NonNull View child, @NonNull View target, int nestedScrollAxes) {
251 | mParentHelper.onNestedScrollAccepted(child, target, nestedScrollAxes);
252 | startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
253 | }
254 |
255 | @Override
256 | public void onStopNestedScroll(@NonNull View target) {
257 | mParentHelper.onStopNestedScroll(target);
258 | stopNestedScroll();
259 | }
260 |
261 | @Override
262 | public void onNestedScroll(@NonNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed,
263 | int dyUnconsumed) {
264 | dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, null);
265 | }
266 |
267 | @Override
268 | public void onNestedPreScroll(@NonNull View target, int dx, int dy, @NonNull int[] consumed) {
269 | dispatchNestedPreScroll(dx, dy, consumed, null);
270 | }
271 |
272 | @Override
273 | public boolean onNestedFling(@NonNull View target, float velocityX, float velocityY, boolean consumed) {
274 | return dispatchNestedFling(velocityX, velocityY, consumed);
275 | }
276 |
277 | @Override
278 | public boolean onNestedPreFling(@NonNull View target, float velocityX, float velocityY) {
279 | return dispatchNestedPreFling(velocityX, velocityY);
280 | }
281 |
282 | @Override
283 | public int getNestedScrollAxes() {
284 | return mParentHelper.getNestedScrollAxes();
285 | }
286 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/hjq/nested/scroll/layout/NestedScrollLinearLayout.java:
--------------------------------------------------------------------------------
1 | package com.hjq.nested.scroll.layout;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.support.annotation.NonNull;
6 | import android.support.v4.view.NestedScrollingChild;
7 | import android.support.v4.view.NestedScrollingChildHelper;
8 | import android.support.v4.view.NestedScrollingParent;
9 | import android.support.v4.view.NestedScrollingParentHelper;
10 | import android.support.v4.view.ViewCompat;
11 | import android.util.AttributeSet;
12 | import android.view.MotionEvent;
13 | import android.view.VelocityTracker;
14 | import android.view.View;
15 | import android.view.ViewConfiguration;
16 | import android.view.ViewParent;
17 | import android.widget.LinearLayout;
18 |
19 | /**
20 | * author : Android 轮子哥
21 | * github : https://github.com/getActivity/NestedScrollLayout
22 | * time : 2023/07/02
23 | * desc : 支持嵌套滚动的 LinearLayout
24 | */
25 | public class NestedScrollLinearLayout extends LinearLayout implements NestedScrollingChild, NestedScrollingParent {
26 |
27 | private static final int INVALID_POINTER = -1;
28 |
29 | private final NestedScrollingChildHelper mChildHelper;
30 | private final NestedScrollingParentHelper mParentHelper;
31 |
32 | private final int[] mScrollConsumed = new int[2];
33 | private final int[] mScrollOffset = new int[2];
34 |
35 | private final float mTouchSlop;
36 | private final float mMaximumVelocity;
37 | private final float mMinimumVelocity;
38 |
39 | private int mLastMotionY;
40 | private int mActivePointerId;
41 |
42 | private VelocityTracker mVelocityTracker;
43 |
44 | private boolean mBeingDragged;
45 |
46 | public NestedScrollLinearLayout(Context context) {
47 | this(context, null, 0);
48 | }
49 |
50 | public NestedScrollLinearLayout(Context context, AttributeSet attrs) {
51 | this(context, attrs, 0);
52 | }
53 |
54 | public NestedScrollLinearLayout(Context context, AttributeSet attrs, int defStyle) {
55 | super(context, attrs, defStyle);
56 | setWillNotDraw(false);
57 | mChildHelper = new NestedScrollingChildHelper(this);
58 | mParentHelper = new NestedScrollingParentHelper(this);
59 | setNestedScrollingEnabled(true);
60 | mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
61 | mMaximumVelocity = ViewConfiguration.get(getContext()).getScaledMaximumFlingVelocity();
62 | mMinimumVelocity = ViewConfiguration.get(getContext()).getScaledMinimumFlingVelocity();
63 | }
64 |
65 | @SuppressLint("ClickableViewAccessibility")
66 | @Override
67 | public boolean onTouchEvent(MotionEvent ev) {
68 | MotionEvent event = MotionEvent.obtain(ev);
69 | initVelocityTrackerIfNotExists();
70 | final int actionMasked = event.getActionMasked();
71 |
72 | switch (actionMasked) {
73 | case MotionEvent.ACTION_DOWN: {
74 | mVelocityTracker.addMovement(ev);
75 |
76 | mLastMotionY = (int) event.getY();
77 | mActivePointerId = event.getPointerId(0);
78 | startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
79 | break;
80 | }
81 | case MotionEvent.ACTION_MOVE:
82 | final int activePointerIndex = event.findPointerIndex(mActivePointerId);
83 | if (activePointerIndex == -1) {
84 | break;
85 | }
86 |
87 | final int y = (int) event.getY(activePointerIndex);
88 | int deltaY = mLastMotionY - y;
89 |
90 | if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
91 | deltaY -= mScrollConsumed[1];
92 | event.offsetLocation(0, mScrollOffset[1]);
93 | }
94 | if (!mBeingDragged && Math.abs(mLastMotionY - y) > mTouchSlop) {
95 | final ViewParent parent = getParent();
96 | if (parent != null) {
97 | parent.requestDisallowInterceptTouchEvent(true);
98 | }
99 | mBeingDragged = true;
100 | if (deltaY > 0) {
101 | deltaY -= mTouchSlop;
102 | } else {
103 | deltaY += mTouchSlop;
104 | }
105 | }
106 |
107 | if (mBeingDragged) {
108 | mVelocityTracker.addMovement(ev);
109 |
110 | mLastMotionY = y - mScrollOffset[1];
111 | if (dispatchNestedScroll(0, 0, 0, deltaY, mScrollOffset)) {
112 | mLastMotionY -= mScrollOffset[1];
113 | event.offsetLocation(0, mScrollOffset[1]);
114 | }
115 | }
116 | break;
117 | case MotionEvent.ACTION_CANCEL:
118 | case MotionEvent.ACTION_UP:
119 | if (mBeingDragged) {
120 | mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
121 | int initialVelocity = (int) mVelocityTracker.getYVelocity(mActivePointerId);
122 |
123 | if (Math.abs(initialVelocity) > mMinimumVelocity) {
124 | flingWithNestedDispatch(-initialVelocity) ;
125 | }
126 | }
127 | mActivePointerId = INVALID_POINTER;
128 | endDrag();
129 | break;
130 | case MotionEvent.ACTION_POINTER_DOWN: {
131 | final int index = event.getActionIndex();
132 | mLastMotionY = (int) event.getY(index);
133 | mActivePointerId = event.getPointerId(index);
134 | break;
135 | }
136 | case MotionEvent.ACTION_POINTER_UP:
137 | onSecondaryPointerUp(event);
138 | mLastMotionY = (int) event.getY(event.findPointerIndex(mActivePointerId));
139 | break;
140 | default:
141 | break;
142 | }
143 |
144 | event.recycle();
145 | return true;
146 | }
147 |
148 | private void onSecondaryPointerUp(MotionEvent ev) {
149 | final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
150 | >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
151 | final int pointerId = ev.getPointerId(pointerIndex);
152 | if (pointerId == mActivePointerId) {
153 | final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
154 | mLastMotionY = (int) ev.getY(newPointerIndex);
155 | mActivePointerId = ev.getPointerId(newPointerIndex);
156 | if (mVelocityTracker != null) {
157 | mVelocityTracker.clear();
158 | }
159 | }
160 | }
161 |
162 | private void endDrag() {
163 | mBeingDragged = false;
164 | recycleVelocityTracker();
165 | stopNestedScroll();
166 | }
167 |
168 | private void flingWithNestedDispatch(int velocityY) {
169 | if (!dispatchNestedPreFling(0, velocityY)) {
170 | dispatchNestedFling(0, velocityY, true);
171 | }
172 | }
173 |
174 | private void initVelocityTrackerIfNotExists() {
175 | if (mVelocityTracker == null) {
176 | mVelocityTracker = VelocityTracker.obtain();
177 | }
178 | }
179 |
180 | private void recycleVelocityTracker() {
181 | if (mVelocityTracker != null) {
182 | mVelocityTracker.recycle();
183 | mVelocityTracker = null;
184 | }
185 | }
186 |
187 | @Override
188 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
189 | if (disallowIntercept) {
190 | recycleVelocityTracker();
191 | }
192 | super.requestDisallowInterceptTouchEvent(disallowIntercept);
193 | }
194 |
195 | // NestedScrollingChild
196 |
197 | @Override
198 | public void setNestedScrollingEnabled(boolean enabled) {
199 | mChildHelper.setNestedScrollingEnabled(enabled);
200 | }
201 |
202 | @Override
203 | public boolean isNestedScrollingEnabled() {
204 | return mChildHelper.isNestedScrollingEnabled();
205 | }
206 |
207 | @Override
208 | public boolean startNestedScroll(int axes) {
209 | return mChildHelper.startNestedScroll(axes);
210 | }
211 |
212 | @Override
213 | public void stopNestedScroll() {
214 | mChildHelper.stopNestedScroll();
215 | }
216 |
217 | @Override
218 | public boolean hasNestedScrollingParent() {
219 | return mChildHelper.hasNestedScrollingParent();
220 | }
221 |
222 | @Override
223 | public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow) {
224 | return mChildHelper.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, offsetInWindow);
225 | }
226 |
227 | @Override
228 | public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow) {
229 | return mChildHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow);
230 | }
231 |
232 | @Override
233 | public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed) {
234 | return mChildHelper.dispatchNestedFling(velocityX, velocityY, consumed);
235 | }
236 |
237 | @Override
238 | public boolean dispatchNestedPreFling(float velocityX, float velocityY) {
239 | return mChildHelper.dispatchNestedPreFling(velocityX, velocityY);
240 | }
241 |
242 | // NestedScrollingParent
243 |
244 | @Override
245 | public boolean onStartNestedScroll(@NonNull View child, @NonNull View target, int nestedScrollAxes) {
246 | return (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0;
247 | }
248 |
249 | @Override
250 | public void onNestedScrollAccepted(@NonNull View child, @NonNull View target, int nestedScrollAxes) {
251 | mParentHelper.onNestedScrollAccepted(child, target, nestedScrollAxes);
252 | startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
253 | }
254 |
255 | @Override
256 | public void onStopNestedScroll(@NonNull View target) {
257 | mParentHelper.onStopNestedScroll(target);
258 | stopNestedScroll();
259 | }
260 |
261 | @Override
262 | public void onNestedScroll(@NonNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed,
263 | int dyUnconsumed) {
264 | dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, null);
265 | }
266 |
267 | @Override
268 | public void onNestedPreScroll(@NonNull View target, int dx, int dy, @NonNull int[] consumed) {
269 | dispatchNestedPreScroll(dx, dy, consumed, null);
270 | }
271 |
272 | @Override
273 | public boolean onNestedFling(@NonNull View target, float velocityX, float velocityY, boolean consumed) {
274 | return dispatchNestedFling(velocityX, velocityY, consumed);
275 | }
276 |
277 | @Override
278 | public boolean onNestedPreFling(@NonNull View target, float velocityX, float velocityY) {
279 | return dispatchNestedPreFling(velocityX, velocityY);
280 | }
281 |
282 | @Override
283 | public int getNestedScrollAxes() {
284 | return mParentHelper.getNestedScrollAxes();
285 | }
286 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/hjq/nested/scroll/layout/NestedScrollRelativeLayout.java:
--------------------------------------------------------------------------------
1 | package com.hjq.nested.scroll.layout;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.support.annotation.NonNull;
6 | import android.support.v4.view.NestedScrollingChild;
7 | import android.support.v4.view.NestedScrollingChildHelper;
8 | import android.support.v4.view.NestedScrollingParent;
9 | import android.support.v4.view.NestedScrollingParentHelper;
10 | import android.support.v4.view.ViewCompat;
11 | import android.util.AttributeSet;
12 | import android.view.MotionEvent;
13 | import android.view.VelocityTracker;
14 | import android.view.View;
15 | import android.view.ViewConfiguration;
16 | import android.view.ViewParent;
17 | import android.widget.RelativeLayout;
18 |
19 | /**
20 | * author : Android 轮子哥
21 | * github : https://github.com/getActivity/NestedScrollLayout
22 | * time : 2023/07/02
23 | * desc : 支持嵌套滚动的 FrameLayout
24 | */
25 | public class NestedScrollRelativeLayout extends RelativeLayout implements NestedScrollingChild, NestedScrollingParent {
26 |
27 | private static final int INVALID_POINTER = -1;
28 |
29 | private final NestedScrollingChildHelper mChildHelper;
30 | private final NestedScrollingParentHelper mParentHelper;
31 |
32 | private final int[] mScrollConsumed = new int[2];
33 | private final int[] mScrollOffset = new int[2];
34 |
35 | private final float mTouchSlop;
36 | private final float mMaximumVelocity;
37 | private final float mMinimumVelocity;
38 |
39 | private int mLastMotionY;
40 | private int mActivePointerId;
41 |
42 | private VelocityTracker mVelocityTracker;
43 |
44 | private boolean mBeingDragged;
45 |
46 | public NestedScrollRelativeLayout(Context context) {
47 | this(context, null, 0);
48 | }
49 |
50 | public NestedScrollRelativeLayout(Context context, AttributeSet attrs) {
51 | this(context, attrs, 0);
52 | }
53 |
54 | public NestedScrollRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
55 | super(context, attrs, defStyle);
56 | setWillNotDraw(false);
57 | mChildHelper = new NestedScrollingChildHelper(this);
58 | mParentHelper = new NestedScrollingParentHelper(this);
59 | setNestedScrollingEnabled(true);
60 | mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
61 | mMaximumVelocity = ViewConfiguration.get(getContext()).getScaledMaximumFlingVelocity();
62 | mMinimumVelocity = ViewConfiguration.get(getContext()).getScaledMinimumFlingVelocity();
63 | }
64 |
65 | @SuppressLint("ClickableViewAccessibility")
66 | @Override
67 | public boolean onTouchEvent(MotionEvent ev) {
68 | MotionEvent event = MotionEvent.obtain(ev);
69 | initVelocityTrackerIfNotExists();
70 | final int actionMasked = event.getActionMasked();
71 |
72 | switch (actionMasked) {
73 | case MotionEvent.ACTION_DOWN: {
74 | mVelocityTracker.addMovement(ev);
75 |
76 | mLastMotionY = (int) event.getY();
77 | mActivePointerId = event.getPointerId(0);
78 | startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
79 | break;
80 | }
81 | case MotionEvent.ACTION_MOVE:
82 | final int activePointerIndex = event.findPointerIndex(mActivePointerId);
83 | if (activePointerIndex == -1) {
84 | break;
85 | }
86 |
87 | final int y = (int) event.getY(activePointerIndex);
88 | int deltaY = mLastMotionY - y;
89 |
90 | if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
91 | deltaY -= mScrollConsumed[1];
92 | event.offsetLocation(0, mScrollOffset[1]);
93 | }
94 | if (!mBeingDragged && Math.abs(mLastMotionY - y) > mTouchSlop) {
95 | final ViewParent parent = getParent();
96 | if (parent != null) {
97 | parent.requestDisallowInterceptTouchEvent(true);
98 | }
99 | mBeingDragged = true;
100 | if (deltaY > 0) {
101 | deltaY -= mTouchSlop;
102 | } else {
103 | deltaY += mTouchSlop;
104 | }
105 | }
106 |
107 | if (mBeingDragged) {
108 | mVelocityTracker.addMovement(ev);
109 |
110 | mLastMotionY = y - mScrollOffset[1];
111 | if (dispatchNestedScroll(0, 0, 0, deltaY, mScrollOffset)) {
112 | mLastMotionY -= mScrollOffset[1];
113 | event.offsetLocation(0, mScrollOffset[1]);
114 | }
115 | }
116 | break;
117 | case MotionEvent.ACTION_CANCEL:
118 | case MotionEvent.ACTION_UP:
119 | if (mBeingDragged) {
120 | mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
121 | int initialVelocity = (int) mVelocityTracker.getYVelocity(mActivePointerId);
122 |
123 | if (Math.abs(initialVelocity) > mMinimumVelocity) {
124 | flingWithNestedDispatch(-initialVelocity) ;
125 | }
126 | }
127 | mActivePointerId = INVALID_POINTER;
128 | endDrag();
129 | break;
130 | case MotionEvent.ACTION_POINTER_DOWN: {
131 | final int index = event.getActionIndex();
132 | mLastMotionY = (int) event.getY(index);
133 | mActivePointerId = event.getPointerId(index);
134 | break;
135 | }
136 | case MotionEvent.ACTION_POINTER_UP:
137 | onSecondaryPointerUp(event);
138 | mLastMotionY = (int) event.getY(event.findPointerIndex(mActivePointerId));
139 | break;
140 | default:
141 | break;
142 | }
143 |
144 | event.recycle();
145 | return true;
146 | }
147 |
148 | private void onSecondaryPointerUp(MotionEvent ev) {
149 | final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
150 | >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
151 | final int pointerId = ev.getPointerId(pointerIndex);
152 | if (pointerId == mActivePointerId) {
153 | final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
154 | mLastMotionY = (int) ev.getY(newPointerIndex);
155 | mActivePointerId = ev.getPointerId(newPointerIndex);
156 | if (mVelocityTracker != null) {
157 | mVelocityTracker.clear();
158 | }
159 | }
160 | }
161 |
162 | private void endDrag() {
163 | mBeingDragged = false;
164 | recycleVelocityTracker();
165 | stopNestedScroll();
166 | }
167 |
168 | private void flingWithNestedDispatch(int velocityY) {
169 | if (!dispatchNestedPreFling(0, velocityY)) {
170 | dispatchNestedFling(0, velocityY, true);
171 | }
172 | }
173 |
174 | private void initVelocityTrackerIfNotExists() {
175 | if (mVelocityTracker == null) {
176 | mVelocityTracker = VelocityTracker.obtain();
177 | }
178 | }
179 |
180 | private void recycleVelocityTracker() {
181 | if (mVelocityTracker != null) {
182 | mVelocityTracker.recycle();
183 | mVelocityTracker = null;
184 | }
185 | }
186 |
187 | @Override
188 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
189 | if (disallowIntercept) {
190 | recycleVelocityTracker();
191 | }
192 | super.requestDisallowInterceptTouchEvent(disallowIntercept);
193 | }
194 |
195 | // NestedScrollingChild
196 |
197 | @Override
198 | public void setNestedScrollingEnabled(boolean enabled) {
199 | mChildHelper.setNestedScrollingEnabled(enabled);
200 | }
201 |
202 | @Override
203 | public boolean isNestedScrollingEnabled() {
204 | return mChildHelper.isNestedScrollingEnabled();
205 | }
206 |
207 | @Override
208 | public boolean startNestedScroll(int axes) {
209 | return mChildHelper.startNestedScroll(axes);
210 | }
211 |
212 | @Override
213 | public void stopNestedScroll() {
214 | mChildHelper.stopNestedScroll();
215 | }
216 |
217 | @Override
218 | public boolean hasNestedScrollingParent() {
219 | return mChildHelper.hasNestedScrollingParent();
220 | }
221 |
222 | @Override
223 | public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow) {
224 | return mChildHelper.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, offsetInWindow);
225 | }
226 |
227 | @Override
228 | public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow) {
229 | return mChildHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow);
230 | }
231 |
232 | @Override
233 | public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed) {
234 | return mChildHelper.dispatchNestedFling(velocityX, velocityY, consumed);
235 | }
236 |
237 | @Override
238 | public boolean dispatchNestedPreFling(float velocityX, float velocityY) {
239 | return mChildHelper.dispatchNestedPreFling(velocityX, velocityY);
240 | }
241 |
242 | // NestedScrollingParent
243 |
244 | @Override
245 | public boolean onStartNestedScroll(@NonNull View child, @NonNull View target, int nestedScrollAxes) {
246 | return (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0;
247 | }
248 |
249 | @Override
250 | public void onNestedScrollAccepted(@NonNull View child, @NonNull View target, int nestedScrollAxes) {
251 | mParentHelper.onNestedScrollAccepted(child, target, nestedScrollAxes);
252 | startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
253 | }
254 |
255 | @Override
256 | public void onStopNestedScroll(@NonNull View target) {
257 | mParentHelper.onStopNestedScroll(target);
258 | stopNestedScroll();
259 | }
260 |
261 | @Override
262 | public void onNestedScroll(@NonNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed,
263 | int dyUnconsumed) {
264 | dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, null);
265 | }
266 |
267 | @Override
268 | public void onNestedPreScroll(@NonNull View target, int dx, int dy, @NonNull int[] consumed) {
269 | dispatchNestedPreScroll(dx, dy, consumed, null);
270 | }
271 |
272 | @Override
273 | public boolean onNestedFling(@NonNull View target, float velocityX, float velocityY, boolean consumed) {
274 | return dispatchNestedFling(velocityX, velocityY, consumed);
275 | }
276 |
277 | @Override
278 | public boolean onNestedPreFling(@NonNull View target, float velocityX, float velocityY) {
279 | return dispatchNestedPreFling(velocityX, velocityY);
280 | }
281 |
282 | @Override
283 | public int getNestedScrollAxes() {
284 | return mParentHelper.getNestedScrollAxes();
285 | }
286 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/hjq/nested/scroll/layout/NestedScrollViewPager.java:
--------------------------------------------------------------------------------
1 | package com.hjq.nested.scroll.layout;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.view.NestedScrollingChild;
7 | import android.support.v4.view.NestedScrollingChildHelper;
8 | import android.support.v4.view.NestedScrollingParent;
9 | import android.support.v4.view.NestedScrollingParentHelper;
10 | import android.support.v4.view.ViewCompat;
11 | import android.support.v4.view.ViewPager;
12 | import android.util.AttributeSet;
13 | import android.view.View;
14 |
15 | /**
16 | * author : Android 轮子哥
17 | * github : https://github.com/getActivity/NestedScrollLayout
18 | * time : 2023/07/02
19 | * desc : 支持嵌套滚动的 ViewPager
20 | */
21 | public class NestedScrollViewPager extends ViewPager implements NestedScrollingParent, NestedScrollingChild {
22 |
23 | private final NestedScrollingParentHelper mParentHelper;
24 | private final NestedScrollingChildHelper mChildHelper;
25 |
26 | public NestedScrollViewPager(@NonNull Context context) {
27 | this(context, null);
28 | }
29 |
30 | public NestedScrollViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
31 | super(context, attrs);
32 |
33 | mParentHelper = new NestedScrollingParentHelper(this);
34 | mChildHelper = new NestedScrollingChildHelper(this);
35 | setNestedScrollingEnabled(true);
36 | }
37 |
38 | @Override
39 | public void setNestedScrollingEnabled(boolean enabled) {
40 | mChildHelper.setNestedScrollingEnabled(enabled);
41 | }
42 |
43 | @Override
44 | public boolean isNestedScrollingEnabled() {
45 | return mChildHelper.isNestedScrollingEnabled();
46 | }
47 |
48 | @Override
49 | public boolean startNestedScroll(int axes) {
50 | return mChildHelper.startNestedScroll(axes);
51 | }
52 |
53 | @Override
54 | public void stopNestedScroll() {
55 | mChildHelper.stopNestedScroll();
56 | }
57 |
58 | @Override
59 | public boolean hasNestedScrollingParent() {
60 | return mChildHelper.hasNestedScrollingParent();
61 | }
62 |
63 | @Override
64 | public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow) {
65 | return mChildHelper.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, offsetInWindow);
66 | }
67 |
68 | @Override
69 | public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow) {
70 | return mChildHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow);
71 | }
72 |
73 | @Override
74 | public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed) {
75 | return mChildHelper.dispatchNestedFling(velocityX, velocityY, consumed);
76 | }
77 |
78 | @Override
79 | public boolean dispatchNestedPreFling(float velocityX, float velocityY) {
80 | return mChildHelper.dispatchNestedPreFling(velocityX, velocityY);
81 | }
82 |
83 | @Override
84 | public boolean onStartNestedScroll(@NonNull View child, @NonNull View target, int nestedScrollAxes) {
85 | return (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0;
86 | }
87 |
88 | @Override
89 | public void onNestedScrollAccepted(@NonNull View child, @NonNull View target, int nestedScrollAxes) {
90 | mParentHelper.onNestedScrollAccepted(child, target, nestedScrollAxes);
91 | startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
92 | }
93 |
94 | @Override
95 | public void onStopNestedScroll(@NonNull View target) {
96 | mParentHelper.onStopNestedScroll(target);
97 | stopNestedScroll();
98 | }
99 |
100 | @Override
101 | public void onNestedScroll(@NonNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
102 | dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, null);
103 | }
104 |
105 | @Override
106 | public void onNestedPreScroll(@NonNull View target, int dx, int dy, @NonNull int[] consumed) {
107 | dispatchNestedPreScroll(dx, dy, consumed, null);
108 | }
109 |
110 | @Override
111 | public boolean onNestedFling(@NonNull View target, float velocityX, float velocityY, boolean consumed) {
112 | return dispatchNestedFling(velocityX, velocityY, consumed);
113 | }
114 |
115 | @Override
116 | public boolean onNestedPreFling(@NonNull View target, float velocityX, float velocityY) {
117 | return dispatchNestedPreFling(velocityX, velocityY);
118 | }
119 |
120 | @Override
121 | public int getNestedScrollAxes() {
122 | return mParentHelper.getNestedScrollAxes();
123 | }
124 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/hjq/nested/scroll/layout/NestedScrollWebView.java:
--------------------------------------------------------------------------------
1 | package com.hjq.nested.scroll.layout;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.support.v4.view.NestedScrollingChild;
6 | import android.support.v4.view.NestedScrollingChildHelper;
7 | import android.support.v4.view.ViewCompat;
8 | import android.util.AttributeSet;
9 | import android.view.MotionEvent;
10 | import android.webkit.WebView;
11 |
12 | /**
13 | * author : Android 轮子哥
14 | * github : https://github.com/getActivity/NestedScrollLayout
15 | * time : 2020/08/18
16 | * desc : 支持嵌套滚动的 WebView
17 | */
18 | public class NestedScrollWebView extends WebView implements NestedScrollingChild {
19 |
20 | private final NestedScrollingChildHelper mChildHelper;
21 |
22 | private int mLastMotionY;
23 |
24 | private final int[] mScrollOffset = new int[2];
25 | private final int[] mScrollConsumed = new int[2];
26 |
27 | private int mNestedOffsetY;
28 | private boolean mChange;
29 |
30 | public NestedScrollWebView(Context context) {
31 | super(context);
32 | }
33 |
34 | public NestedScrollWebView(Context context, AttributeSet attrs) {
35 | super(context, attrs);
36 | }
37 |
38 | public NestedScrollWebView(Context context, AttributeSet attrs, int defStyleAttr) {
39 | super(context, attrs, defStyleAttr);
40 | }
41 |
42 | public NestedScrollWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
43 | super(context, attrs, defStyleAttr, defStyleRes);
44 | }
45 |
46 | {
47 | mChildHelper = new NestedScrollingChildHelper(this);
48 | setNestedScrollingEnabled(true);
49 | }
50 |
51 | @SuppressLint("ClickableViewAccessibility")
52 | @Override
53 | public boolean onTouchEvent(MotionEvent event) {
54 | boolean result = false;
55 |
56 | MotionEvent trackedEvent = MotionEvent.obtain(event);
57 |
58 | final int action = event.getActionMasked();
59 |
60 | if (action == MotionEvent.ACTION_DOWN) {
61 | mNestedOffsetY = 0;
62 | }
63 |
64 | int y = (int) event.getY();
65 |
66 | event.offsetLocation(0, mNestedOffsetY);
67 |
68 | switch (action) {
69 | case MotionEvent.ACTION_DOWN:
70 | mChange = false;
71 | mLastMotionY = y;
72 | startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
73 | result = super.onTouchEvent(event);
74 | break;
75 | case MotionEvent.ACTION_MOVE:
76 | int deltaY = mLastMotionY - y;
77 |
78 | if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
79 | deltaY -= mScrollConsumed[1];
80 | trackedEvent.offsetLocation(0, mScrollOffset[1]);
81 | mNestedOffsetY += mScrollOffset[1];
82 | }
83 |
84 | mLastMotionY = y - mScrollOffset[1];
85 |
86 | int oldY = getScrollY();
87 | int newScrollY = Math.max(0, oldY + deltaY);
88 | int dyConsumed = newScrollY - oldY;
89 | int dyUnconsumed = deltaY - dyConsumed;
90 |
91 | if (dispatchNestedScroll(0, dyConsumed, 0, dyUnconsumed, mScrollOffset)) {
92 | mLastMotionY -= mScrollOffset[1];
93 | trackedEvent.offsetLocation(0, mScrollOffset[1]);
94 | mNestedOffsetY += mScrollOffset[1];
95 | }
96 |
97 | if(mScrollConsumed[1] == 0 && mScrollOffset[1] == 0) {
98 | if(mChange) {
99 | mChange =false;
100 | trackedEvent.setAction(MotionEvent.ACTION_DOWN);
101 | super.onTouchEvent(trackedEvent);
102 | } else {
103 | result = super.onTouchEvent(trackedEvent);
104 | }
105 | trackedEvent.recycle();
106 | } else{
107 | if(!mChange) {
108 | mChange = true;
109 | super.onTouchEvent(MotionEvent.obtain(0,0,MotionEvent.ACTION_CANCEL,0,0,0));
110 | }
111 | }
112 |
113 | //result = super.onTouchEvent(trackedEvent);
114 | //trackedEvent.recycle();
115 | break;
116 | case MotionEvent.ACTION_POINTER_DOWN:
117 | case MotionEvent.ACTION_POINTER_UP:
118 | case MotionEvent.ACTION_UP:
119 | case MotionEvent.ACTION_CANCEL:
120 | stopNestedScroll();
121 | result = super.onTouchEvent(event);
122 | break;
123 | default:
124 | break;
125 | }
126 | return result;
127 | }
128 |
129 | /**
130 | * {@link NestedScrollingChild}
131 | */
132 |
133 | @Override
134 | public void setNestedScrollingEnabled(boolean enabled) {
135 | mChildHelper.setNestedScrollingEnabled(enabled);
136 | }
137 |
138 | @Override
139 | public boolean isNestedScrollingEnabled() {
140 | return mChildHelper.isNestedScrollingEnabled();
141 | }
142 |
143 | @Override
144 | public boolean startNestedScroll(int axes) {
145 | return mChildHelper.startNestedScroll(axes);
146 | }
147 |
148 | @Override
149 | public void stopNestedScroll() {
150 | mChildHelper.stopNestedScroll();
151 | }
152 |
153 | @Override
154 | public boolean hasNestedScrollingParent() {
155 | return mChildHelper.hasNestedScrollingParent();
156 | }
157 |
158 | @Override
159 | public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow) {
160 | return mChildHelper.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, offsetInWindow);
161 | }
162 |
163 | @Override
164 | public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow) {
165 | return mChildHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow);
166 | }
167 |
168 | @Override
169 | public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed) {
170 | return mChildHelper.dispatchNestedFling(velocityX, velocityY, consumed);
171 | }
172 |
173 | @Override
174 | public boolean dispatchNestedPreFling(float velocityX, float velocityY) {
175 | return mChildHelper.dispatchNestedPreFling(velocityX, velocityY);
176 | }
177 | }
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/getActivity/NestedScrollLayout/ecff3891e04f31be080f5446d6610c1116ff6315/logo.png
--------------------------------------------------------------------------------
/picture/download_demo_apk_qr_code.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/getActivity/NestedScrollLayout/ecff3891e04f31be080f5446d6610c1116ff6315/picture/download_demo_apk_qr_code.png
--------------------------------------------------------------------------------
/picture/dynamic_figure.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/getActivity/NestedScrollLayout/ecff3891e04f31be080f5446d6610c1116ff6315/picture/dynamic_figure.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------