├── .gitignore
├── .idea
├── codeStyles
│ └── Project.xml
├── gradle.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── study
│ │ └── yang
│ │ └── stackcardviewgroup
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── study
│ │ │ └── yang
│ │ │ └── stackcardviewgroup
│ │ │ ├── DefineConfig.java
│ │ │ ├── DefineLeftLayoutManager.java
│ │ │ ├── DefineRightLayoutManager.java
│ │ │ ├── DefineStackAdapter.java
│ │ │ ├── Main2Activity.java
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── animator
│ │ └── item_animator.xml
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable-xxhdpi
│ │ ├── ic_app_logo.png
│ │ └── quick_question_num.png
│ │ ├── drawable
│ │ ├── circle_shape.xml
│ │ ├── ic_launcher_background.xml
│ │ ├── quick_follow_question_rectangle.xml
│ │ ├── superposition_item_shape_1.xml
│ │ ├── superposition_item_shape_2.xml
│ │ └── superposition_item_shape_3.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── activity_main2.xml
│ │ ├── include_item_card.xml
│ │ ├── item_card.xml
│ │ ├── superposition_item_card.xml
│ │ └── vertical_item_card.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── study
│ └── yang
│ └── stackcardviewgroup
│ └── ExampleUnitTest.java
├── build.gradle
├── gif
└── 1553694295757.gif
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # IntelliJ
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/assetWizardSettings.xml
41 | .idea/dictionaries
42 | .idea/libraries
43 | .idea/caches
44 |
45 | # Keystore files
46 | # Uncomment the following line if you do not want to check your keystore files in.
47 | #*.jks
48 |
49 | # External native build folder generated in Android Studio 2.2 and later
50 | .externalNativeBuild
51 |
52 | # Google Services (e.g. APIs or Firebase)
53 | google-services.json
54 |
55 | # Freeline
56 | freeline.py
57 | freeline/
58 | freeline_project_description.json
59 |
60 | # fastlane
61 | fastlane/report.xml
62 | fastlane/Preview.html
63 | fastlane/screenshots
64 | fastlane/test_output
65 | fastlane/readme.md
66 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # StackCardViewGroup
2 | 自定义LayoutManager实现卡片叠加控件
3 | 效果图
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "study.yang.stackcardviewgroup"
7 | minSdkVersion 19
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:28.0.0'
24 | testImplementation 'junit:junit:4.12'
25 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
26 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
27 |
28 | implementation 'com.jakewharton:butterknife:8.8.1'
29 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
30 | implementation 'com.github.bumptech.glide:glide:3.8.0'
31 | implementation 'com.makeramen:roundedimageview:2.3.0'
32 | implementation 'com.android.support:recyclerview-v7:28.0.0'
33 | implementation 'com.android.support:cardview-v7:28.0.0'
34 | api 'de.hdodenhof:circleimageview:2.2.0'
35 | }
36 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/study/yang/stackcardviewgroup/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package study.yang.stackcardviewgroup;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("study.yang.stackcardviewgroup", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/study/yang/stackcardviewgroup/DefineConfig.java:
--------------------------------------------------------------------------------
1 | package study.yang.stackcardviewgroup;
2 |
3 | import android.support.annotation.FloatRange;
4 | import android.support.annotation.IntRange;
5 |
6 |
7 | /**
8 | * 布局管理器的配置参数
9 | */
10 | public class DefineConfig {
11 |
12 | @IntRange(from = 2)
13 | public int space = 60;
14 | public int initialStackCount = 0;
15 | @FloatRange(from = 0f, to = 1f)
16 | public float scaleRatio;
17 |
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/java/study/yang/stackcardviewgroup/DefineLeftLayoutManager.java:
--------------------------------------------------------------------------------
1 | package study.yang.stackcardviewgroup;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.ObjectAnimator;
6 | import android.content.Context;
7 | import android.support.v4.view.ViewCompat;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.util.DisplayMetrics;
10 | import android.util.Log;
11 | import android.view.MotionEvent;
12 | import android.view.VelocityTracker;
13 | import android.view.View;
14 | import android.view.ViewConfiguration;
15 | import android.view.ViewGroup;
16 |
17 | import java.lang.reflect.InvocationTargetException;
18 | import java.lang.reflect.Method;
19 |
20 |
21 | public class DefineLeftLayoutManager extends RecyclerView.LayoutManager {
22 |
23 | /**
24 | * 基准控件的宽度
25 | */
26 | private int mDecorateWidth;
27 | /**
28 | * 基准控件的高度
29 | */
30 | private int mDecorateHeight;
31 | /**
32 | * 默认间隔,单位为px
33 | */
34 | private int space = 45;
35 | /**
36 | * 默认展示数量
37 | */
38 | private int initStackCount = 3;
39 | /**
40 | * 手机屏幕宽度
41 | */
42 | private int widthPixels;
43 | /**
44 | * 手机屏幕高度
45 | */
46 | private final int heightPixels;
47 | /**
48 | * 以基准尺寸为基数的缩放比例
49 | */
50 | private float scaleRatio = 0.2f;
51 |
52 | /**
53 | * 总的偏移量
54 | */
55 | private int mTotalOffsetDx = 0;
56 | /**
57 | * 第一个可视item的下标
58 | */
59 | private int currentIndex = 0;
60 | /**
61 | * 最后一个可视item的下标,最后一个item的透明度为0
62 | */
63 | private int endIndex = 0;
64 |
65 | //基准值的比例
66 | private float referenceValue = 0f;
67 | //缩放和平移的系数
68 | private float k = 0f;
69 | //速度跟踪者
70 | private VelocityTracker mVelocityTracker = VelocityTracker.obtain();
71 | //动画处理
72 | private ObjectAnimator animator;
73 | /**
74 | * 动画的偏移值
75 | */
76 | private int animateValue;
77 |
78 | private int duration = 300;
79 | private int lastAnimateValue;
80 | /**
81 | * 判断指针ID
82 | */
83 | private int pointerId;
84 | /**
85 | * 水平方向上的最低速度
86 | */
87 | private int mMinVelocityX;
88 |
89 | private RecyclerView.Recycler recycler;
90 | private RecyclerView.State state;
91 | private Context context;
92 |
93 |
94 | public DefineLeftLayoutManager(Context context, DefineConfig defineConfig) {
95 | this.context = context;
96 | space = defineConfig.space;
97 | initStackCount = defineConfig.initialStackCount;
98 | scaleRatio = defineConfig.scaleRatio;
99 | DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
100 | widthPixels = displayMetrics.widthPixels;
101 | heightPixels = displayMetrics.heightPixels;
102 | }
103 |
104 | @Override
105 | public RecyclerView.LayoutParams generateDefaultLayoutParams() {
106 | return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
107 | }
108 |
109 | @Override
110 | public boolean isAutoMeasureEnabled() {
111 | return true;
112 | }
113 |
114 | @Override
115 | public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
116 | /**
117 | * 当adapter中的子View数目为0时解绑recycler中的控件
118 | */
119 | if (getItemCount() == 0) {
120 | detachAndScrapAttachedViews(recycler);
121 | return;
122 | }
123 | /**
124 | * state.isPreLayout判断layoutManager执行到哪一个哪一个阶段
125 | * 返回true表示执行到预布局阶段
126 | */
127 | if (getChildCount() == 0 && state.isPreLayout()) {
128 | return;
129 | }
130 | if (getChildCount() == 0) {
131 | View scrap = recycler.getViewForPosition(0);
132 | /**
133 | * 获取执行一个fling操作的最小速度
134 | */
135 | mMinVelocityX = ViewConfiguration.get(scrap.getContext()).getScaledMinimumFlingVelocity();
136 | measureChildWithMargins(scrap, 0, 0);
137 | //根据给定的space以及initStackCount换算出第一个View的宽度
138 | mDecorateWidth = widthPixels - (initStackCount + 1) * space;// getDecoratedMeasurementHorizontal(scrap);
139 | //获取控件的高度
140 | mDecorateHeight = getDecoratedMeasuredHeight(scrap);
141 | //给基准值赋值
142 | referenceValue = scaleRatio * mDecorateWidth + space;
143 | k = space * 1.0f / referenceValue;
144 |
145 | }
146 |
147 | //初始化时调用 填充childView
148 | fill(0, recycler, state);
149 | }
150 |
151 | private int fill(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
152 |
153 | try {
154 | /**
155 | * 第一个可视itemView的下标等于0且mTotalOffsetDx的值等于且继续往右滑动时不处理
156 | * 偏移总量除于基准值得到的结果大于等于adapter最后一个item下标且dx>0时不处理
157 | */
158 | if ((currentIndex == 0 && dx < 0 && mTotalOffsetDx == 0)/*||mTotalOffsetDx< 0 */ || (mTotalOffsetDx / referenceValue >= getItemCount() - 1 && dx > 0)) {
159 | return 0;
160 | }
161 | //避免滑动过快,所以每次除以基准值求余
162 | mTotalOffsetDx += (dx % referenceValue);
163 | //解绑RecyclerView上的View,调用此方法之后getChildCount为0
164 | detachAndScrapAttachedViews(recycler);
165 | currentIndex = (int) (mTotalOffsetDx / referenceValue);
166 | //计算尾部下标
167 | int compute = currentIndex + initStackCount;
168 | endIndex = compute >= getItemCount() ? getItemCount() - 1 : compute;
169 |
170 | for (int i = currentIndex; i <= endIndex; i++) {
171 |
172 | //获取当前位置的控件
173 | View view = recycler.getViewForPosition(i);
174 |
175 |
176 | addView(view);//现在重新添加
177 | //测量子控件的上下左右的位置
178 | measureChildWithMargins(view, 0, 0);
179 |
180 | int rightMargin = (initStackCount - (i - currentIndex)) * space;
181 | float scale = 1 - (i - currentIndex) * scaleRatio;
182 | int currentWidth = calculateCurrentWidth(i, scale);
183 | int currentHeight = calculateCurrentHeight(i, scale);
184 |
185 | /**
186 | * - scaleX * offsetDx将水平移动的偏移量跟子控件向左偏移的速度联系起来
187 | */
188 | int left = 0;//(i + 1) * space;//
189 | float offsetDx = mTotalOffsetDx % referenceValue;
190 |
191 | if (currentIndex == i) {
192 | left = (int) (widthPixels - mDecorateWidth - rightMargin - offsetDx);
193 | } else {
194 | left = (int) (widthPixels - currentWidth - rightMargin - k * offsetDx);
195 | }
196 |
197 | if (left < space && i == getItemCount() - 1) {
198 | left = space;
199 | mTotalOffsetDx = (int) (referenceValue * (getItemCount() - 1));
200 | } else if (left > space && i == 0) {
201 | left = space;
202 | mTotalOffsetDx = 0;
203 | }
204 |
205 | int right = left + currentWidth;
206 |
207 |
208 | /**
209 | * 以自身为基准点
210 | */
211 | view.setPivotX(getDecoratedMeasuredWidth(view));
212 | view.setPivotY(getDecoratedMeasuredHeight(view) * 1.0f / 2);
213 | view.setScaleX(currentWidth * 1.0f / getDecoratedMeasuredWidth(view));
214 | view.setScaleY(currentWidth * 1.0f / getDecoratedMeasuredWidth(view));
215 | layoutDecoratedWithMargins(view, right - getDecoratedMeasuredWidth(view), 0, right, getDecoratedMeasuredHeight(view));
216 |
217 | //setTranslationZ存在BUG,elevation是z轴上的静态值而translationZ是z轴上的动态值
218 | //此处的elevation过高的话会导致控件阴影过大
219 | ViewCompat.setElevation(view, currentHeight * 0.0001f);
220 |
221 |
222 | //正常下标移动的时候透明度走if,反之走else
223 | if (endIndex - currentIndex == initStackCount) {
224 | if (i == currentIndex) {
225 | view.setAlpha(1 - offsetDx / referenceValue);
226 | } else if (i == endIndex /*&& endIndex != getItemCount() - 1*/) { ///*&& endIndex != getItemCount() - 1*/不能要,否则到最后四条时显示不出来最后一个
227 | view.setAlpha(offsetDx / referenceValue);
228 | } else {
229 | view.setAlpha(1);
230 | }
231 | } else {//处理小于initStackCount个数的可视itemView的透明度处理
232 | if (i == currentIndex) {
233 | view.setAlpha(1 - offsetDx / referenceValue);
234 | } else {
235 | view.setAlpha(1);
236 | }
237 | }
238 | }
239 | return dx;
240 | } catch (IndexOutOfBoundsException e) {
241 | e.printStackTrace();
242 | }
243 | return 0;
244 |
245 | }
246 |
247 | /**
248 | * 计算当前控件的宽度
249 | *
250 | * @param position
251 | * @param scale 为1时,widthSpace为0
252 | * @return
253 | */
254 | private int calculateCurrentWidth(int position, float scale) {
255 | float offsetDx = mTotalOffsetDx % referenceValue;
256 | if (offsetDx > 0/* && offsetDx <= referenceValue*/) {
257 | if (currentIndex == position) {
258 | scale = 1 - offsetDx / referenceValue;
259 | } else {
260 | //临时的偏移比例
261 | float tempRatio = offsetDx * scaleRatio / referenceValue;
262 | //临时的缩放比例
263 | float tempScaleX = scale + tempRatio;
264 | scale = tempScaleX >= 1 ? 1f : tempScaleX;
265 | }
266 | }
267 | return (int) (mDecorateWidth * scale);
268 | }
269 |
270 | private int calculateCurrentHeight(int position, float scale) {
271 | float offsetDx = mTotalOffsetDx % referenceValue;
272 | if (offsetDx > 0 /*&& offsetDx <= referenceValue*/) {
273 | if (currentIndex == position) {
274 | scale = 1 - offsetDx * 1.0f / referenceValue;
275 | } else {
276 | /**
277 | * scaleX + offsetDx * 1.0f / heightSpace用来计算在scale的基础之上来重新制定scaleY
278 | */
279 | float tempRatio = offsetDx * scaleRatio / referenceValue;
280 | float tempScaleY = scale + tempRatio;
281 | scale = tempScaleY >= 1 ? 1f : tempScaleY;
282 | }
283 | }
284 | return (int) (mDecorateHeight * scale);
285 | }
286 |
287 | @Override
288 | public void onAdapterChanged(RecyclerView.Adapter oldAdapter, RecyclerView.Adapter newAdapter) {
289 | super.onAdapterChanged(oldAdapter, newAdapter);
290 | }
291 |
292 | @Override
293 | public boolean canScrollHorizontally() {
294 | return true;
295 | }
296 |
297 |
298 | public int findLastVisibleItemPosition() {
299 | View childAt = getChildAt(0);
300 | return getPosition(childAt);
301 | }
302 |
303 |
304 | /**
305 | * action_move时会调用该方法
306 | *
307 | * @param dx
308 | * @param recycler
309 | * @param state
310 | * @return
311 | */
312 | @Override
313 | public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
314 | this.recycler = recycler;
315 | this.state = state;
316 | recyclerUnVisibleView(recycler, dx);
317 | fill(dx, recycler, state);
318 | return dx;
319 | }
320 |
321 |
322 | /**
323 | * 回收不可见的childview
324 | */
325 | private void recyclerUnVisibleView(RecyclerView.Recycler recycler, int dx) {
326 | if (getChildCount() > 0) {
327 | //得到第一个可见的View
328 |
329 | if (dx > 0) {//向左
330 | View firstView = getChildAt(0);
331 | if (firstView.getWidth() < space) {
332 | //从RecycleView中移除View,将view给与给定的Recycler从而达到复用的目的
333 | removeAndRecycleView(firstView, recycler);
334 | }
335 | //得到第一个可见View在Adapter中的位置
336 | } else if (dx < 0) {
337 | Log.e("childCount", "recycler::中View的个数" + getChildCount());
338 | }
339 | }
340 | }
341 |
342 | private RecyclerView mRV;
343 |
344 | /**
345 | * 当控件依附于Window时调用
346 | *
347 | * @param view
348 | */
349 | @Override
350 | public void onAttachedToWindow(RecyclerView view) {
351 | super.onAttachedToWindow(view);
352 | mRV = view;
353 | view.setOnTouchListener(touchListener);
354 | view.setOnFlingListener(flingListener);
355 | }
356 |
357 |
358 | private RecyclerView.OnFlingListener flingListener = new RecyclerView.OnFlingListener() {
359 | /**
360 | * 设置就算是飞滑也只让控件移动一个referenceValue的位置
361 | * @param velocityX 向左滑 velocityX>0 向右滑<0
362 | * @param velocityY
363 | * @return
364 | */
365 | @Override
366 | public boolean onFling(int velocityX, int velocityY) {
367 | int scrollX;
368 | float offsetDx = mTotalOffsetDx % referenceValue;
369 | int tempScrollX = (int) (referenceValue - offsetDx);
370 | int vel = absMax(velocityX, velocityY);
371 | if (vel > 0) {
372 | //向左快速滑动的时候,补全下一个移动位的距离
373 | scrollX = tempScrollX;
374 | } else {
375 | //向右快速滑动的时候,将总偏移量除以referenceValue的
376 | //余数部分给减去,从而达到mTotalOffsetDx除以referenceValue能够等于整数
377 | scrollX = (int) -offsetDx;
378 | }
379 |
380 | int dur = computeSettleDuration(Math.abs(scrollX), Math.abs(vel));
381 | brewAndStartAnimator(dur, scrollX);
382 | setScrollStateIdle();
383 | return true;
384 | }
385 | };
386 |
387 | /**
388 | * 计算控件停下来的所需要的时间
389 | *
390 | * @param distance
391 | * @param xvel
392 | * @return
393 | */
394 | private int computeSettleDuration(int distance, float xvel) {
395 | float sWeight = 0.5f * distance / referenceValue;
396 | float velWeight = xvel > 0 ? 0.5f * mMinVelocityX / xvel : 0;
397 |
398 | return (int) ((sWeight + velWeight) * duration);
399 | }
400 |
401 | /**
402 | * 计算飞滑时水平或者竖直方向的最大值
403 | *
404 | * @param a
405 | * @param b
406 | * @return
407 | */
408 | private int absMax(int a, int b) {
409 | if (Math.abs(a) > Math.abs(b))
410 | return a;
411 | else return b;
412 | }
413 |
414 | private Method sSetScrollState;
415 |
416 | /**
417 | * 防止滚动的时候中断点击事件
418 | */
419 | private void setScrollStateIdle() {
420 | try {
421 | if (sSetScrollState == null)
422 | sSetScrollState = RecyclerView.class.getDeclaredMethod("setScrollState", int.class);
423 | sSetScrollState.setAccessible(true);
424 | sSetScrollState.invoke(mRV, RecyclerView.SCROLL_STATE_IDLE);
425 | } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
426 | e.printStackTrace();
427 | }
428 | }
429 |
430 | private View.OnTouchListener touchListener = new View.OnTouchListener() {
431 |
432 | @Override
433 | public boolean onTouch(View v, MotionEvent event) {
434 | //将触摸事件交给速度跟踪者事件
435 | mVelocityTracker.addMovement(event);
436 | switch (event.getAction()) {
437 | case MotionEvent.ACTION_DOWN:
438 | if (animator != null && animator.isRunning())
439 | animator.cancel();
440 | pointerId = event.getPointerId(0);
441 | break;
442 | case MotionEvent.ACTION_UP:
443 | //点击事件
444 | if (v.isPressed()) v.performClick();
445 | mVelocityTracker.computeCurrentVelocity(1000, 14000);
446 | //获取当前pointerId水平方向上的速度
447 | float xVelocity = mVelocityTracker.getXVelocity(pointerId);
448 | float offsetDx = mTotalOffsetDx % referenceValue;
449 | int scrollX;
450 | if (Math.abs(xVelocity) < mMinVelocityX /*&& offsetDx != 0*/) {
451 | //因为referenceValue / 6时第一个视图高度和第二视图高度相等
452 | if (offsetDx >= referenceValue / 6) {
453 | scrollX = (int) (referenceValue - offsetDx);
454 | } else {
455 | scrollX = (int) -offsetDx;
456 | }
457 | int dur = (int) (Math.abs((scrollX + 0f) / referenceValue) * duration);
458 | brewAndStartAnimator(dur, scrollX);
459 | }
460 | break;
461 | }
462 | return false;
463 | }
464 | };
465 |
466 | private void brewAndStartAnimator(int dur, int finalXorY) {
467 | /**
468 | * 动画的值由0到finalY
469 | */
470 | animator = ObjectAnimator.ofInt(this, "animateValue", 0, finalXorY);
471 | animator.setDuration(dur);
472 | animator.start();
473 | animator.addListener(new AnimatorListenerAdapter() {
474 | @Override
475 | public void onAnimationEnd(Animator animation) {
476 | lastAnimateValue = 0;
477 |
478 | }
479 |
480 | @Override
481 | public void onAnimationCancel(Animator animation) {
482 | lastAnimateValue = 0;
483 | }
484 | });
485 | }
486 |
487 | /**
488 | * 属性动画执行时调用
489 | *
490 | * @param animateValue
491 | */
492 | @SuppressWarnings("unused")
493 | public void setAnimateValue(int animateValue) {
494 | this.animateValue = animateValue;
495 | int distance = this.animateValue - lastAnimateValue;
496 | scrollHorizontallyBy(distance, recycler, state);
497 | lastAnimateValue = animateValue;
498 | }
499 |
500 | /**
501 | * 属性动画执行时调用
502 | *
503 | * @param
504 | */
505 | @SuppressWarnings("unused")
506 | public int getAnimateValue() {
507 | return animateValue;
508 | }
509 |
510 | }
511 |
--------------------------------------------------------------------------------
/app/src/main/java/study/yang/stackcardviewgroup/DefineRightLayoutManager.java:
--------------------------------------------------------------------------------
1 | package study.yang.stackcardviewgroup;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.ObjectAnimator;
6 | import android.content.Context;
7 | import android.support.v4.view.ViewCompat;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.util.DisplayMetrics;
10 | import android.util.Log;
11 | import android.view.MotionEvent;
12 | import android.view.VelocityTracker;
13 | import android.view.View;
14 | import android.view.ViewConfiguration;
15 | import android.view.ViewGroup;
16 |
17 | import java.lang.reflect.InvocationTargetException;
18 | import java.lang.reflect.Method;
19 |
20 |
21 | public class DefineRightLayoutManager extends RecyclerView.LayoutManager {
22 |
23 | /**
24 | * 基准控件的宽度
25 | */
26 | private int mDecorateWidth;
27 | /**
28 | * 基准控件的高度
29 | */
30 | private int mDecorateHeight;
31 | /**
32 | * 默认间隔,单位为px
33 | */
34 | private int space = 45;
35 | /**
36 | * 默认展示数量
37 | */
38 | private int initStackCount = 3;
39 | /**
40 | * 手机屏幕宽度
41 | */
42 | private int widthPixels;
43 | /**
44 | * 手机屏幕高度
45 | */
46 | private final int heightPixels;
47 | /**
48 | * 以基准尺寸为基数的缩放比例
49 | */
50 | private float scaleRatio = 0.2f;
51 |
52 | /**
53 | * 总的偏移量
54 | */
55 | private int mTotalOffsetDx = 0;
56 | /**
57 | * 第一个可视item的下标
58 | */
59 | private int currentIndex = 0;
60 | /**
61 | * 最后一个可视item的下标,最后一个item的透明度为0
62 | */
63 | private int endIndex = 0;
64 |
65 | //基准值的比例
66 | private float referenceValue = 0f;
67 | //缩放和平移的系数
68 | private float k = 0f;
69 | //速度跟踪者
70 | private VelocityTracker mVelocityTracker = VelocityTracker.obtain();
71 | //动画处理
72 | private ObjectAnimator animator;
73 | /**
74 | * 动画的偏移值
75 | */
76 | private int animateValue;
77 |
78 | private int duration = 300;
79 | private int lastAnimateValue;
80 | /**
81 | * 判断指针ID
82 | */
83 | private int pointerId;
84 | /**
85 | * 水平方向上的最低速度
86 | */
87 | private int mMinVelocityX;
88 |
89 | private RecyclerView.Recycler recycler;
90 | private RecyclerView.State state;
91 | private Context context;
92 |
93 |
94 |
95 | public DefineRightLayoutManager(Context context, DefineConfig defineConfig) {
96 | this.context = context;
97 | space = defineConfig.space;
98 | initStackCount = defineConfig.initialStackCount;
99 | scaleRatio = defineConfig.scaleRatio;
100 |
101 | DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
102 | widthPixels = displayMetrics.widthPixels;
103 | heightPixels = displayMetrics.heightPixels;
104 | }
105 |
106 | @Override
107 | public RecyclerView.LayoutParams generateDefaultLayoutParams() {
108 | return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
109 | }
110 |
111 | @Override
112 | public boolean isAutoMeasureEnabled() {
113 | return true;
114 | }
115 |
116 | @Override
117 | public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
118 | /**
119 | * 当adapter中的子View数目为0时解绑recycler中的控件
120 | */
121 | if (getItemCount() == 0) {
122 | detachAndScrapAttachedViews(recycler);
123 | return;
124 | }
125 | /**
126 | * state.isPreLayout判断layoutManager执行到哪一个哪一个阶段
127 | * 返回true表示执行到预布局阶段
128 | */
129 | if (getChildCount() == 0 && state.isPreLayout()) {
130 | return;
131 | }
132 | if (getChildCount() == 0) {
133 | View scrap = recycler.getViewForPosition(0);
134 | /**
135 | * 获取执行一个fling操作的最小速度
136 | */
137 | mMinVelocityX = ViewConfiguration.get(scrap.getContext()).getScaledMinimumFlingVelocity();
138 | measureChildWithMargins(scrap, 0, 0);
139 | //根据给定的space以及initStackCount换算出第一个View的宽度
140 | mDecorateWidth = widthPixels - (initStackCount + 1) * space;// getDecoratedMeasurementHorizontal(scrap);
141 | //获取控件的高度
142 | mDecorateHeight = getDecoratedMeasuredHeight(scrap);
143 | //给基准值赋值
144 | referenceValue = scaleRatio * mDecorateWidth + space;
145 | k = space * 1.0f / referenceValue;
146 |
147 | }
148 |
149 | //初始化时调用 填充childView
150 | fill(0, recycler, state);
151 | }
152 |
153 | private int fill(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
154 |
155 | try {
156 | if ((currentIndex == 0 && dx > 0 && mTotalOffsetDx == 0)/*||mTotalOffsetDx< 0 */ || (Math.abs(mTotalOffsetDx) / referenceValue >= getItemCount() - 1 && dx < 0)) {
157 | return 0;
158 | }
159 | //避免滑动过快,所以每次除以基准值求余
160 | mTotalOffsetDx += (dx % referenceValue);
161 | //解绑RecyclerView上的View,调用此方法之后getChildCount为0
162 | detachAndScrapAttachedViews(recycler);
163 | currentIndex = (int) (Math.abs(mTotalOffsetDx) / referenceValue);
164 | //计算尾部下标
165 | int compute = currentIndex + initStackCount;
166 | endIndex = compute >= getItemCount() ? getItemCount() - 1 : compute;
167 |
168 | for (int i = currentIndex; i <= endIndex; i++) {
169 |
170 | //获取当前位置的控件
171 | View view = recycler.getViewForPosition(i);
172 |
173 |
174 | addView(view);//现在重新添加
175 | //测量子控件的上下左右的位置
176 | measureChildWithMargins(view, 0, 0);
177 |
178 | int leftMargin = (initStackCount - (i - currentIndex)) * space;
179 | float scale = 1 - (i - currentIndex) * scaleRatio;
180 | int currentWidth = calculateCurrentWidth(i, scale);
181 | int currentHeight = calculateCurrentHeight(i, scale);
182 |
183 | /**
184 | * - scaleX * offsetDx将水平移动的偏移量跟子控件向左偏移的速度联系起来
185 | */
186 | int right = 0;//(i + 1) * space;//
187 | float offsetDx = mTotalOffsetDx % referenceValue;
188 |
189 | if (currentIndex == i) {
190 | right = (int) (mDecorateWidth + leftMargin - offsetDx);
191 | } else {
192 | right = (int) (currentWidth + leftMargin - k * offsetDx);
193 | }
194 |
195 | if (right > (widthPixels - space) && i == getItemCount() - 1) {
196 | right = widthPixels - space;
197 | mTotalOffsetDx = -(int) (referenceValue * (getItemCount() - 1));
198 | } else if (right < widthPixels - space && i == 0) {
199 | right = widthPixels - space;
200 | mTotalOffsetDx = 0;
201 | }
202 |
203 | // int right = left + currentWidth;
204 |
205 |
206 | /**
207 | * 以自身为基准点
208 | */
209 | view.setPivotX(getDecoratedMeasuredWidth(view));
210 | view.setPivotY(getDecoratedMeasuredHeight(view) * 1.0f / 2);
211 | view.setScaleX(currentWidth * 1.0f / getDecoratedMeasuredWidth(view));
212 | view.setScaleY(currentWidth * 1.0f / getDecoratedMeasuredWidth(view));
213 | layoutDecoratedWithMargins(view, right - getDecoratedMeasuredWidth(view), 0, right, getDecoratedMeasuredHeight(view));
214 |
215 | //setTranslationZ存在BUG,elevation是z轴上的静态值而translationZ是z轴上的动态值
216 | //此处的elevation过高的话会导致控件阴影过大
217 | ViewCompat.setElevation(view, currentHeight * 0.0001f);
218 |
219 |
220 | //正常下标移动的时候透明度走if,反之走else
221 | if (endIndex - currentIndex == initStackCount) {
222 | if (i == currentIndex) {
223 | view.setAlpha(1 - Math.abs(offsetDx) / referenceValue);
224 | } else if (i == endIndex /*&& endIndex != getItemCount() - 1*/) { ///*&& endIndex != getItemCount() - 1*/不能要,否则到最后四条时显示不出来最后一个
225 | view.setAlpha(Math.abs(offsetDx) / referenceValue);
226 | } else {
227 | view.setAlpha(1);
228 | }
229 | } else {//处理小于initStackCount个数的可视itemView的透明度处理
230 | if (i == currentIndex) {
231 | view.setAlpha(1 - Math.abs(offsetDx) / referenceValue);
232 | } else {
233 | view.setAlpha(1);
234 | }
235 | }
236 | }
237 | return dx;
238 | } catch (IndexOutOfBoundsException e) {
239 | e.printStackTrace();
240 | }
241 | return 0;
242 |
243 | }
244 |
245 | /**
246 | * 计算当前控件的宽度
247 | *
248 | * @param position
249 | * @param scale 为1时,widthSpace为0
250 | * @return
251 | */
252 | private int calculateCurrentWidth(int position, float scale) {
253 | float offsetDx = Math.abs(mTotalOffsetDx) % referenceValue;
254 | if (offsetDx > 0/* && offsetDx <= referenceValue*/) {
255 | if (currentIndex == position) {
256 | scale = 1 - offsetDx / referenceValue;
257 | } else {
258 | //临时的偏移比例
259 | float tempRatio = offsetDx * scaleRatio / referenceValue;
260 | //临时的缩放比例
261 | float tempScaleX = scale + tempRatio;
262 | scale = tempScaleX >= 1 ? 1f : tempScaleX;
263 | }
264 | }
265 | return (int) (mDecorateWidth * scale);
266 | }
267 |
268 | private int calculateCurrentHeight(int position, float scale) {
269 | float offsetDx = Math.abs(mTotalOffsetDx) % referenceValue;
270 | if (offsetDx > 0 /*&& offsetDx <= referenceValue*/) {
271 | if (currentIndex == position) {
272 | scale = 1 - offsetDx * 1.0f / referenceValue;
273 | } else {
274 | /**
275 | * scaleX + offsetDx * 1.0f / heightSpace用来计算在scale的基础之上来重新制定scaleY
276 | */
277 | float tempRatio = offsetDx * scaleRatio / referenceValue;
278 | float tempScaleY = scale + tempRatio;
279 | scale = tempScaleY >= 1 ? 1f : tempScaleY;
280 | }
281 | }
282 | return (int) (mDecorateHeight * scale);
283 | }
284 |
285 | @Override
286 | public void onAdapterChanged(RecyclerView.Adapter oldAdapter, RecyclerView.Adapter newAdapter) {
287 | super.onAdapterChanged(oldAdapter, newAdapter);
288 | }
289 |
290 | @Override
291 | public boolean canScrollHorizontally() {
292 | return true;
293 | }
294 |
295 |
296 | public int findLastVisibleItemPosition() {
297 | View childAt = getChildAt(0);
298 | return getPosition(childAt);
299 | }
300 |
301 |
302 | /**
303 | * action_move时会调用该方法
304 | *
305 | * @param dx
306 | * @param recycler
307 | * @param state
308 | * @return
309 | */
310 | @Override
311 | public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
312 | this.recycler = recycler;
313 | this.state = state;
314 | recyclerUnVisibleView(recycler, dx);
315 | fill(dx, recycler, state);
316 | return dx;
317 | }
318 |
319 |
320 | /**
321 | * 回收不可见的childview
322 | */
323 | private void recyclerUnVisibleView(RecyclerView.Recycler recycler, int dx) {
324 | if (getChildCount() > 0) {
325 | //得到第一个可见的View
326 |
327 | if (dx < 0) {//向左
328 | View firstView = getChildAt(0);
329 | if (firstView.getWidth() < space) {
330 | //从RecycleView中移除View,将view给与给定的Recycler从而达到复用的目的
331 | removeAndRecycleView(firstView, recycler);
332 | }
333 | //得到第一个可见View在Adapter中的位置
334 | } else if (dx > 0) {
335 | Log.e("childCount", "recycler::中View的个数" + getChildCount());
336 | }
337 | }
338 | }
339 |
340 | private RecyclerView mRV;
341 |
342 | /**
343 | * 当控件依附于Window时调用
344 | *
345 | * @param view
346 | */
347 | @Override
348 | public void onAttachedToWindow(RecyclerView view) {
349 | super.onAttachedToWindow(view);
350 | mRV = view;
351 | view.setOnTouchListener(touchListener);
352 | view.setOnFlingListener(flingListener);
353 | }
354 |
355 |
356 | private RecyclerView.OnFlingListener flingListener = new RecyclerView.OnFlingListener() {
357 | /**
358 | * 设置就算是飞滑也只让控件移动一个referenceValue的位置
359 | * @param velocityX
360 | * @param velocityY
361 | * @return
362 | */
363 | @Override
364 | public boolean onFling(int velocityX, int velocityY) {
365 | int scrollX;
366 | float offsetDx = Math.abs(mTotalOffsetDx) % referenceValue;
367 | int tempScrollX = (int) (referenceValue - offsetDx);
368 | int vel = absMax(velocityX, velocityY);
369 | if (vel < 0) {
370 | //向左快速滑动的时候,补全下一个移动位的距离
371 | scrollX = -tempScrollX;
372 | } else {
373 | //向右快速滑动的时候,将总偏移量除以referenceValue的
374 | //余数部分给减去,从而达到mTotalOffsetDx除以referenceValue能够等于整数
375 | scrollX = (int) offsetDx;
376 | }
377 |
378 |
379 | int dur = computeSettleDuration(Math.abs(scrollX), Math.abs(vel));
380 | brewAndStartAnimator(dur, scrollX);
381 | setScrollStateIdle();
382 | return true;
383 | }
384 | };
385 |
386 | /**
387 | * 计算控件停下来的所需要的时间
388 | *
389 | * @param distance
390 | * @param xvel
391 | * @return
392 | */
393 | private int computeSettleDuration(int distance, float xvel) {
394 | float sWeight = 0.5f * distance / referenceValue;
395 | float velWeight = xvel > 0 ? 0.5f * mMinVelocityX / xvel : 0;
396 |
397 | return (int) ((sWeight + velWeight) * duration);
398 | }
399 |
400 | /**
401 | * 计算飞滑时水平或者竖直方向的最大值
402 | *
403 | * @param a
404 | * @param b
405 | * @return
406 | */
407 | private int absMax(int a, int b) {
408 | if (Math.abs(a) > Math.abs(b))
409 | return a;
410 | else return b;
411 | }
412 |
413 | private Method sSetScrollState;
414 |
415 | /**
416 | * 防止滚动的时候中断点击事件
417 | */
418 | private void setScrollStateIdle() {
419 | try {
420 | if (sSetScrollState == null)
421 | sSetScrollState = RecyclerView.class.getDeclaredMethod("setScrollState", int.class);
422 | sSetScrollState.setAccessible(true);
423 | sSetScrollState.invoke(mRV, RecyclerView.SCROLL_STATE_IDLE);
424 | } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
425 | e.printStackTrace();
426 | }
427 | }
428 |
429 | private View.OnTouchListener touchListener = new View.OnTouchListener() {
430 |
431 | @Override
432 | public boolean onTouch(View v, MotionEvent event) {
433 | //将触摸事件交给速度跟踪者事件
434 | mVelocityTracker.addMovement(event);
435 | switch (event.getAction()) {
436 | case MotionEvent.ACTION_DOWN:
437 | if (animator != null && animator.isRunning())
438 | animator.cancel();
439 | pointerId = event.getPointerId(0);
440 | break;
441 | case MotionEvent.ACTION_UP:
442 | //点击事件
443 | if (v.isPressed()) v.performClick();
444 | mVelocityTracker.computeCurrentVelocity(1000, 14000);
445 | //获取当前pointerId水平方向上的速度
446 | float xVelocity = mVelocityTracker.getXVelocity(pointerId);
447 | float offsetDx = Math.abs(mTotalOffsetDx) % referenceValue;
448 | int scrollX;
449 | if (Math.abs(xVelocity) < mMinVelocityX /*&& offsetDx != 0*/) {
450 | //因为referenceValue / 6时第一个视图高度和第二视图高度相等
451 | if (offsetDx >= referenceValue / 6) {
452 | scrollX = -(int) (referenceValue - offsetDx);
453 | } else {
454 | scrollX = (int) offsetDx;
455 | }
456 | int dur = (int) (Math.abs((scrollX + 0f) / referenceValue) * duration);
457 | brewAndStartAnimator(dur, scrollX);
458 | }
459 | break;
460 | }
461 | return false;
462 | }
463 | };
464 |
465 | private void brewAndStartAnimator(int dur, int finalXorY) {
466 | animator = ObjectAnimator.ofInt(this, "animateValue", 0, finalXorY);
467 | animator.setDuration(dur);
468 | animator.start();
469 | animator.addListener(new AnimatorListenerAdapter() {
470 | @Override
471 | public void onAnimationEnd(Animator animation) {
472 | lastAnimateValue = 0;
473 |
474 | }
475 |
476 | @Override
477 | public void onAnimationCancel(Animator animation) {
478 | lastAnimateValue = 0;
479 | }
480 | });
481 | }
482 |
483 | /**
484 | * 属性动画执行时调用
485 | *
486 | * @param animateValue
487 | */
488 | @SuppressWarnings("unused")
489 | public void setAnimateValue(int animateValue) {
490 | this.animateValue = animateValue;
491 | int distance = this.animateValue - lastAnimateValue;
492 | scrollHorizontallyBy(distance, recycler, state);
493 | lastAnimateValue = animateValue;
494 | }
495 |
496 | /**
497 | * 属性动画执行时调用
498 | *
499 | * @param
500 | */
501 | @SuppressWarnings("unused")
502 | public int getAnimateValue() {
503 | return animateValue;
504 | }
505 |
506 | }
507 |
--------------------------------------------------------------------------------
/app/src/main/java/study/yang/stackcardviewgroup/DefineStackAdapter.java:
--------------------------------------------------------------------------------
1 | package study.yang.stackcardviewgroup;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.Toast;
9 |
10 | import java.util.Arrays;
11 | import java.util.List;
12 |
13 | /**
14 | * Created by CJJ on 2017/3/7.
15 | */
16 |
17 | public class DefineStackAdapter extends RecyclerView.Adapter {
18 |
19 | private LayoutInflater inflater;
20 | private List datas;
21 | private Context context;
22 |
23 |
24 | public DefineStackAdapter(Context context, List datas) {
25 | this.context = context;
26 | this.datas = datas;
27 | }
28 |
29 | @Override
30 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
31 | if (inflater == null) {
32 | context = parent.getContext();
33 | inflater = LayoutInflater.from(parent.getContext());
34 | }
35 | /**
36 | * 用此方法创建控件,用root的LayoutParams来约束子布局
37 | */
38 | View inflate = inflater.inflate(R.layout.superposition_item_card, parent, false);
39 | // View inflate =View.inflate(context,R.layout.superposition_item_card,null);
40 | return new ViewHolder(inflate);
41 |
42 | }
43 |
44 |
45 | @Override
46 | public void onBindViewHolder(ViewHolder holder, int position) {
47 | switch (position % 3) {
48 | case 0:
49 | holder.itemView.setBackgroundResource(R.drawable.superposition_item_shape_1);
50 | break;
51 | case 1:
52 | holder.itemView.setBackgroundResource(R.drawable.superposition_item_shape_2);
53 | break;
54 | case 2:
55 | holder.itemView.setBackgroundResource(R.drawable.superposition_item_shape_3);
56 | break;
57 | }
58 | }
59 |
60 | @Override
61 | public int getItemCount() {
62 | return datas == null ? 0 : datas.size();
63 | }
64 |
65 | class ViewHolder extends RecyclerView.ViewHolder {
66 | public ViewHolder(View itemView) {
67 | super(itemView);
68 | itemView.setOnClickListener(new View.OnClickListener() {
69 | @Override
70 | public void onClick(View v) {
71 | Toast.makeText(context.getApplicationContext(), String.valueOf(getAdapterPosition()), Toast.LENGTH_SHORT)
72 | .show();
73 | }
74 | });
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/app/src/main/java/study/yang/stackcardviewgroup/Main2Activity.java:
--------------------------------------------------------------------------------
1 | package study.yang.stackcardviewgroup;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.os.Message;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.util.Log;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | public class Main2Activity extends AppCompatActivity {
14 |
15 | private Handler handler = new Handler() {
16 | @Override
17 | public void handleMessage(Message msg) {
18 | super.handleMessage(msg);
19 | }
20 | };
21 | private DefineStackAdapter defineStackAdapter;
22 | private DefineLeftLayoutManager layoutManager1;
23 | private List datas;
24 | private DefineRightLayoutManager drlm;
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_main2);
30 | RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
31 | RecyclerView rv1 = (RecyclerView) findViewById(R.id.rv_1);
32 |
33 | datas = new ArrayList<>();
34 | for (int i = 0; i < 5; i++) {
35 | datas.add(String.valueOf(i));
36 | }
37 | DefineConfig defineConfig = new DefineConfig();
38 | defineConfig.initialStackCount = 3;
39 | defineConfig.space = 45;
40 | defineConfig.scaleRatio = 0.2f;
41 | layoutManager1 = new DefineLeftLayoutManager(this, defineConfig);
42 | drlm = new DefineRightLayoutManager(this, defineConfig);
43 | rv1.setLayoutManager(drlm);
44 | ArrayList datas2 = new ArrayList<>();
45 | datas2.addAll(datas);
46 | rv1.setAdapter(new DefineStackAdapter(this, datas2));
47 |
48 | defineStackAdapter = new DefineStackAdapter(this, datas);
49 | rv.setLayoutManager(layoutManager1);
50 | rv.setAdapter(defineStackAdapter);
51 | rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
52 | @Override
53 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
54 | super.onScrollStateChanged(recyclerView, newState);
55 | RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
56 | int visibleItemCount = layoutManager.getChildCount();
57 | int totalItemCount = layoutManager.getItemCount();
58 | if ((visibleItemCount > 0 && newState == RecyclerView.SCROLL_STATE_IDLE && (layoutManager1.findLastVisibleItemPosition()) >= totalItemCount - 1)) {
59 | onLoadNextPage(recyclerView);
60 | }
61 | }
62 |
63 | @Override
64 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
65 | super.onScrolled(recyclerView, dx, dy);
66 |
67 | }
68 | });
69 |
70 |
71 | }
72 |
73 | private void onLoadNextPage(RecyclerView recyclerView) {
74 | Log.e("onLoad", "加载到底部了,重新加载数据");
75 | int size = datas.size();
76 | int endSize = (size + 5 > 15) ? 15 : size + 5;
77 | for (int i = size; i < endSize; i++) {
78 | datas.add(String.valueOf(i));
79 | }
80 | defineStackAdapter.notifyDataSetChanged();
81 |
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/app/src/main/java/study/yang/stackcardviewgroup/MainActivity.java:
--------------------------------------------------------------------------------
1 | package study.yang.stackcardviewgroup;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.support.v7.widget.CardView;
6 | import android.util.DisplayMetrics;
7 |
8 | public class MainActivity extends AppCompatActivity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_main);
14 | CardView cv_1 = (CardView) findViewById(R.id.cv_1);
15 | CardView cv_2 = (CardView) findViewById(R.id.cv_2);
16 | CardView cv_4 = (CardView) findViewById(R.id.cv_4);
17 | CardView cv_5 = (CardView) findViewById(R.id.cv_5);
18 | CardView cv_6 = (CardView) findViewById(R.id.cv_6);
19 |
20 | DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
21 | cv_1.measure(0, 0);
22 | cv_1.setPivotX(900);
23 | cv_1.setPivotY(cv_1.getMeasuredHeight() * 1.0f / 2);
24 | float scaleX = 900 * 1.0f / displayMetrics.widthPixels;
25 | cv_1.setScaleX(0.6f);
26 | cv_1.setScaleY(0.6f);
27 |
28 | cv_4.setPivotX(900);
29 | cv_4.setPivotY(cv_1.getMeasuredHeight() * 1.0f / 2);
30 | cv_4.setScaleX(0.6f);
31 | cv_4.setScaleY(0.6f);
32 |
33 | cv_5.setPivotX(900);
34 | cv_5.setPivotY(cv_1.getMeasuredHeight() * 1.0f / 2);
35 | cv_5.setScaleX(0.8f);
36 | cv_5.setScaleY(0.8f);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/res/animator/item_animator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
6 |
7 |
12 |
13 |
14 | -
15 |
16 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_app_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Duckdan/StackCardViewGroup/8771336bb1c2a66ea6768b55f017097ac4cec980/app/src/main/res/drawable-xxhdpi/ic_app_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/quick_question_num.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Duckdan/StackCardViewGroup/8771336bb1c2a66ea6768b55f017097ac4cec980/app/src/main/res/drawable-xxhdpi/quick_question_num.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/circle_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/quick_follow_question_rectangle.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/superposition_item_shape_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/superposition_item_shape_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/superposition_item_shape_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
14 |
18 |
19 |
29 |
30 |
39 |
40 |
44 |
45 |
50 |
51 |
55 |
56 |
60 |
61 |
68 |
69 |
75 |
76 |
77 |
83 |
84 |
85 |
86 |
87 |
93 |
94 |
101 |
102 |
106 |
107 |
116 |
117 |
127 |
128 |
129 |
139 |
140 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
170 |
171 |
181 |
182 |
186 |
187 |
193 |
194 |
198 |
199 |
203 |
204 |
212 |
213 |
220 |
221 |
222 |
229 |
230 |
231 |
232 |
233 |
239 |
240 |
248 |
249 |
253 |
254 |
264 |
265 |
275 |
276 |
277 |
287 |
288 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main2.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
14 |
18 |
19 |
24 |
25 |
26 |
27 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/include_item_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
19 |
20 |
29 |
30 |
34 |
35 |
40 |
41 |
45 |
46 |
50 |
51 |
58 |
59 |
65 |
66 |
67 |
73 |
74 |
75 |
76 |
77 |
83 |
84 |
91 |
92 |
96 |
97 |
106 |
107 |
117 |
118 |
119 |
129 |
130 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
159 |
160 |
169 |
170 |
174 |
175 |
180 |
181 |
185 |
186 |
190 |
191 |
198 |
199 |
205 |
206 |
207 |
213 |
214 |
215 |
216 |
217 |
223 |
224 |
231 |
232 |
236 |
237 |
246 |
247 |
257 |
258 |
259 |
269 |
270 |
283 |
284 |
285 |
286 |
287 |
288 |
298 |
299 |
309 |
310 |
314 |
315 |
321 |
322 |
326 |
327 |
331 |
332 |
340 |
341 |
348 |
349 |
350 |
357 |
358 |
359 |
360 |
361 |
367 |
368 |
376 |
377 |
381 |
382 |
392 |
393 |
403 |
404 |
405 |
415 |
416 |
429 |
430 |
431 |
432 |
433 |
434 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
18 |
19 |
26 |
27 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/superposition_item_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
22 |
23 |
27 |
28 |
34 |
35 |
39 |
40 |
44 |
45 |
53 |
54 |
61 |
62 |
63 |
70 |
71 |
72 |
73 |
74 |
80 |
81 |
89 |
90 |
94 |
95 |
105 |
106 |
116 |
117 |
118 |
128 |
129 |
142 |
143 |
144 |
145 |
146 |
147 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/vertical_item_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
21 |
28 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Duckdan/StackCardViewGroup/8771336bb1c2a66ea6768b55f017097ac4cec980/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Duckdan/StackCardViewGroup/8771336bb1c2a66ea6768b55f017097ac4cec980/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Duckdan/StackCardViewGroup/8771336bb1c2a66ea6768b55f017097ac4cec980/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Duckdan/StackCardViewGroup/8771336bb1c2a66ea6768b55f017097ac4cec980/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Duckdan/StackCardViewGroup/8771336bb1c2a66ea6768b55f017097ac4cec980/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Duckdan/StackCardViewGroup/8771336bb1c2a66ea6768b55f017097ac4cec980/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Duckdan/StackCardViewGroup/8771336bb1c2a66ea6768b55f017097ac4cec980/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Duckdan/StackCardViewGroup/8771336bb1c2a66ea6768b55f017097ac4cec980/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Duckdan/StackCardViewGroup/8771336bb1c2a66ea6768b55f017097ac4cec980/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Duckdan/StackCardViewGroup/8771336bb1c2a66ea6768b55f017097ac4cec980/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | StackCardViewGroup
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/study/yang/stackcardviewgroup/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package study.yang.stackcardviewgroup;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.2.0'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gif/1553694295757.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Duckdan/StackCardViewGroup/8771336bb1c2a66ea6768b55f017097ac4cec980/gif/1553694295757.gif
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
15 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Duckdan/StackCardViewGroup/8771336bb1c2a66ea6768b55f017097ac4cec980/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------