) : RecyclerView.LayoutManager() {
14 | private enum class FlingOrientation{NONE, LEFT_TO_RIGHT, RIGHT_TO_LEFT, TOP_TO_BOTTOM, BOTTOM_TO_TOP}
15 |
16 | enum class ScrollOrientation{LEFT_TO_RIGHT, RIGHT_TO_LEFT, TOP_TO_BOTTOM, BOTTOM_TO_TOP}
17 |
18 | private var mVisibleItemCount = visibleCount
19 |
20 | private var mScrollOrientation = scrollOrientation
21 |
22 | private var mScrollOffset: Int
23 |
24 | private lateinit var mOnScrollListener: RecyclerView.OnScrollListener
25 | private lateinit var mOnFlingListener: RecyclerView.OnFlingListener
26 |
27 | //做动画的组件,支持自定义
28 | private var mAnimation: StackAnimation? = null
29 | //做布局的组件,支持自定义
30 | private var mLayout: StackLayout? = null
31 |
32 | //是否是翻页效果
33 | private var mPagerMode = true
34 |
35 | //触发翻页效果的最低 Fling速度
36 | private var mPagerFlingVelocity = 0
37 |
38 | //标志当前滚动是否是调用scrollToCenter之后触发的滚动
39 | private var mFixScrolling = false
40 |
41 | //fling的方向,用来判断是前翻还是后翻
42 | private var mFlingOrientation = FlingOrientation.NONE
43 |
44 | //当前所处item对应的位置
45 | private var itemPosition = 0
46 |
47 | //判断item位置是否发生了改变
48 | private var isItemPositionChanged = false
49 |
50 | //item 位置发生改变的回调
51 | private var itemChangedListener: ItemChangedListener? = null
52 |
53 | interface ItemChangedListener {
54 | fun onItemChanged(position: Int)
55 | }
56 |
57 | /**
58 | * 设置是否为ViewPager 式翻页模式.
59 | *
60 | * 当设置为 true 的时候,可以配合[StackLayoutManager.setPagerFlingVelocity]设置触发翻页的最小速度.
61 | * @param isPagerMode 这个值默认是 false,当设置为 true 的时候,会有 viewPager 翻页效果.
62 | */
63 | fun setPagerMode(isPagerMode: Boolean) {
64 | mPagerMode = isPagerMode
65 | }
66 |
67 | /**
68 | * @return 当前是否为ViewPager翻页模式.
69 | */
70 | fun getPagerMode(): Boolean {
71 | return mPagerMode
72 | }
73 |
74 | /**
75 | * 设置触发ViewPager翻页效果的最小速度.
76 | *
77 | * 该值仅在 [StackLayoutManager.getPagerMode] == true的时候有效.
78 | * @param velocity 默认值是2000.
79 | */
80 | fun setPagerFlingVelocity(@IntRange(from = 0, to = Int.MAX_VALUE.toLong()) velocity: Int) {
81 | mPagerFlingVelocity = Math.min(Int.MAX_VALUE, Math.max(0, velocity))
82 | }
83 |
84 | /**
85 | * @return 当前触发翻页的最小 fling 速度.
86 | */
87 | fun getPagerFlingVelocity(): Int {
88 | return mPagerFlingVelocity
89 | }
90 |
91 | /**
92 | * 设置recyclerView 静止时候可见的itemView 个数.
93 | * @param count 可见 itemView,默认为3
94 | */
95 | fun setVisibleItemCount(@IntRange(from = 1, to = Long.MAX_VALUE)count: Int) {
96 | mVisibleItemCount = Math.min(itemCount - 1, Math.max(1, count))
97 | mAnimation?.setVisibleCount(mVisibleItemCount)
98 | }
99 |
100 | /**
101 | * 获取recyclerView 静止时候可见的itemView 个数.
102 | * @return 静止时候可见的itemView 个数,默认为3.
103 | */
104 | fun getVisibleItemCount(): Int {
105 | return mVisibleItemCount
106 | }
107 |
108 | /**
109 | * 设置 item 偏移值,即第 i 个 item 相对于 第 i-1个 item 在水平方向的偏移值,默认是40px.
110 | * @param offset 每个 item 相对于前一个的偏移值.
111 | */
112 | fun setItemOffset(offset: Int) {
113 | mLayout?.setItemOffset(offset)
114 | }
115 |
116 | /**
117 | * 获取每个 item 相对于前一个的水平偏移值.
118 | * @return 每个 item 相对于前一个的水平偏移值.
119 | */
120 | fun getItemOffset(): Int {
121 | return if (mLayout == null) {
122 | 0
123 | } else {
124 | mLayout!!.getItemOffset()
125 | }
126 | }
127 |
128 | /**
129 | * 设置item 移动动画.
130 | * @param animation item 移动动画.
131 | */
132 | fun setAnimation(animation: StackAnimation) {
133 | mAnimation = animation
134 | }
135 |
136 | /**
137 | * 获取 item 移动动画.
138 | * @return item 移动动画.
139 | */
140 | fun getAnimation(): StackAnimation? {
141 | return mAnimation
142 | }
143 |
144 | /**
145 | * 获取StackLayoutManager 的滚动方向.
146 | * @return StackLayoutManager 的滚动方向.
147 | */
148 | fun getScrollOrientation(): ScrollOrientation {
149 | return mScrollOrientation
150 | }
151 |
152 | /**
153 | * 返回第一个可见 itemView 的位置.
154 | * @return 返回第一个可见 itemView 的位置.
155 | */
156 | fun getFirstVisibleItemPosition(): Int {
157 | if (width == 0 || height == 0) {
158 | return 0
159 | }
160 | return when(mScrollOrientation) {
161 | ScrollOrientation.RIGHT_TO_LEFT -> Math.floor((mScrollOffset * 1.0 / width)).toInt()
162 | ScrollOrientation.LEFT_TO_RIGHT -> itemCount - 1 - Math.ceil((mScrollOffset * 1.0 / width)).toInt()
163 | ScrollOrientation.BOTTOM_TO_TOP -> Math.floor((mScrollOffset * 1.0 / height)).toInt()
164 | ScrollOrientation.TOP_TO_BOTTOM -> itemCount - 1 - Math.ceil((mScrollOffset * 1.0 / height)).toInt()
165 | }
166 | }
167 |
168 | /**
169 | * 设置 item 位置改变时触发的回调
170 | */
171 | fun setItemChangedListener(listener: ItemChangedListener) {
172 | itemChangedListener = listener
173 | }
174 |
175 | constructor(scrollOrientation: ScrollOrientation) : this(scrollOrientation, 3, DefaultAnimation::class.java, DefaultLayout::class.java)
176 |
177 | constructor(scrollOrientation: ScrollOrientation, visibleCount: Int) : this(scrollOrientation, visibleCount, DefaultAnimation::class.java, DefaultLayout::class.java)
178 |
179 | constructor() : this(ScrollOrientation.RIGHT_TO_LEFT)
180 |
181 | init {
182 | mScrollOffset = when(mScrollOrientation) {
183 | ScrollOrientation.RIGHT_TO_LEFT, ScrollOrientation.BOTTOM_TO_TOP -> 0
184 | else -> Int.MAX_VALUE
185 | }
186 |
187 | if (StackAnimation::class.java.isAssignableFrom(animation)) {
188 | try {
189 | val cla = animation.getDeclaredConstructor(ScrollOrientation::class.java, Int::class.javaPrimitiveType)
190 | mAnimation = cla.newInstance(scrollOrientation, visibleCount) as StackAnimation
191 | } catch (e: Exception) {
192 | e.printStackTrace()
193 | }
194 | }
195 | if (StackLayout::class.java.isAssignableFrom(layout)) {
196 | try {
197 | val cla = layout.getDeclaredConstructor(ScrollOrientation::class.java, Int::class.javaPrimitiveType, Int::class.javaPrimitiveType)
198 | mLayout = cla.newInstance(scrollOrientation, visibleCount, 30) as StackLayout
199 | } catch (e: Exception) {
200 | e.printStackTrace()
201 | }
202 | }
203 | }
204 |
205 | override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams {
206 | return RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
207 | ViewGroup.LayoutParams.WRAP_CONTENT)
208 | }
209 |
210 | override fun onAttachedToWindow(view: RecyclerView) {
211 | super.onAttachedToWindow(view)
212 | mOnFlingListener = object : RecyclerView.OnFlingListener() {
213 | override fun onFling(velocityX: Int, velocityY: Int): Boolean {
214 | if (mPagerMode) {
215 | when(mScrollOrientation) {
216 | ScrollOrientation.RIGHT_TO_LEFT, ScrollOrientation.LEFT_TO_RIGHT -> {
217 | mFlingOrientation = when {
218 | velocityX > mPagerFlingVelocity -> FlingOrientation.RIGHT_TO_LEFT
219 | velocityX < -mPagerFlingVelocity -> FlingOrientation.LEFT_TO_RIGHT
220 | else -> FlingOrientation.NONE
221 | }
222 | if (mScrollOffset in 1 until width * (itemCount - 1)) { //边界不需要滚动
223 | mFixScrolling = true
224 | }
225 | }
226 | else -> {
227 | mFlingOrientation = when {
228 | velocityY > mPagerFlingVelocity -> FlingOrientation.BOTTOM_TO_TOP
229 | velocityY < -mPagerFlingVelocity -> FlingOrientation.TOP_TO_BOTTOM
230 | else -> FlingOrientation.NONE
231 | }
232 | if (mScrollOffset in 1 until width * (itemCount - 1)) { //边界不需要滚动
233 | mFixScrolling = true
234 | }
235 | }
236 | }
237 | calculateAndScrollToTarget(view)
238 | }
239 | return mPagerMode
240 | }
241 | }
242 | view.onFlingListener = mOnFlingListener
243 |
244 | mOnScrollListener = object : RecyclerView.OnScrollListener() {
245 | override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
246 | if (newState == SCROLL_STATE_IDLE) {
247 | if (!mFixScrolling) {
248 | mFixScrolling = true
249 | calculateAndScrollToTarget(view)
250 | } else {
251 | //表示此次 IDLE 是由修正位置结束触发的
252 | mFixScrolling = false
253 | }
254 | } else if (newState == SCROLL_STATE_DRAGGING) {
255 | mFixScrolling = false
256 | }
257 | }
258 | }
259 | view.addOnScrollListener(mOnScrollListener)
260 | }
261 |
262 | override fun onDetachedFromWindow(view: RecyclerView?, recycler: RecyclerView.Recycler?) {
263 | super.onDetachedFromWindow(view, recycler)
264 | if (view?.onFlingListener == mOnFlingListener) {
265 | view.onFlingListener = null
266 | }
267 | view?.removeOnScrollListener(mOnScrollListener)
268 | }
269 |
270 | override fun canScrollHorizontally(): Boolean {
271 | if (itemCount == 0) {
272 | return false
273 | }
274 | return when (mScrollOrientation) {
275 | ScrollOrientation.LEFT_TO_RIGHT, ScrollOrientation.RIGHT_TO_LEFT -> true
276 | else -> false
277 | }
278 | }
279 |
280 | override fun canScrollVertically(): Boolean {
281 | if (itemCount == 0) {
282 | return false
283 | }
284 | return when (mScrollOrientation) {
285 | ScrollOrientation.TOP_TO_BOTTOM, ScrollOrientation.BOTTOM_TO_TOP -> true
286 | else -> false
287 | }
288 | }
289 |
290 | override fun onLayoutChildren(recycler: RecyclerView.Recycler, state: RecyclerView.State) {
291 |
292 | mLayout?.requestLayout()
293 |
294 | removeAndRecycleAllViews(recycler)
295 |
296 | if (itemCount > 0) {
297 | mScrollOffset = getValidOffset(mScrollOffset)
298 | loadItemView(recycler)
299 | }
300 | }
301 |
302 | override fun scrollHorizontallyBy(dx: Int, recycler: RecyclerView.Recycler, state: RecyclerView.State): Int {
303 | return handleScrollBy(dx, recycler)
304 | }
305 |
306 | override fun scrollVerticallyBy(dy: Int, recycler: RecyclerView.Recycler, state: RecyclerView.State?): Int {
307 | return handleScrollBy(dy, recycler)
308 | }
309 |
310 | override fun scrollToPosition(position: Int) {
311 | if (position < 0 || position >= itemCount) {
312 | throw ArrayIndexOutOfBoundsException("$position is out of bound [0..$itemCount-1]")
313 | }
314 | mScrollOffset = getPositionOffset(position)
315 | requestLayout()
316 | }
317 |
318 | override fun smoothScrollToPosition(recyclerView: RecyclerView, state: RecyclerView.State?, position: Int) {
319 | if (position < 0 || position >= itemCount) {
320 | throw ArrayIndexOutOfBoundsException("$position is out of bound [0..$itemCount-1]")
321 | }
322 | mFixScrolling = true
323 | scrollToCenter(position, recyclerView, true)
324 | }
325 |
326 | private fun updatePositionRecordAndNotify(position: Int) {
327 | if (itemChangedListener == null) {
328 | return
329 | }
330 | if (position != itemPosition) {
331 | isItemPositionChanged = true
332 | itemPosition = position
333 | itemChangedListener?.onItemChanged(itemPosition)
334 | } else {
335 | isItemPositionChanged = false
336 | }
337 | }
338 |
339 | private fun handleScrollBy(offset: Int, recycler: RecyclerView.Recycler): Int {
340 | //期望值,不得超过最大最小值,所以期望值不一定等于实际值
341 | val expectOffset = mScrollOffset + offset
342 |
343 | //实际值
344 | mScrollOffset = getValidOffset(expectOffset)
345 |
346 | //实际偏移,超过最大最小值之后的偏移都应该是0,该值作为返回值,否则在极限位置进行滚动的时候不会出现弹性阴影
347 | val exactMove = mScrollOffset - expectOffset + offset
348 |
349 | if (exactMove == 0) {
350 | //itemViews 位置都不会改变,直接 return
351 | return 0
352 | }
353 |
354 | detachAndScrapAttachedViews(recycler)
355 |
356 | loadItemView(recycler)
357 | return exactMove
358 | }
359 |
360 | private fun loadItemView(recycler: RecyclerView.Recycler) {
361 | val firstVisiblePosition = getFirstVisibleItemPosition()
362 | val lastVisiblePosition = getLastVisibleItemPosition()
363 |
364 | //位移百分比
365 | val movePercent = getFirstVisibleItemMovePercent()
366 |
367 | for (i in lastVisiblePosition downTo firstVisiblePosition) {
368 | val view = recycler.getViewForPosition(i)
369 | //添加到recycleView 中
370 | addView(view)
371 | //测量
372 | measureChild(view, 0, 0)
373 | //布局
374 | mLayout?.doLayout(this, mScrollOffset, movePercent, view, i - firstVisiblePosition)
375 | //做动画
376 | mAnimation?.doAnimation(movePercent, view, i - firstVisiblePosition)
377 | }
378 |
379 | //尝试更新当前item的位置并通知外界
380 | updatePositionRecordAndNotify(firstVisiblePosition)
381 |
382 | //重用
383 | if (firstVisiblePosition - 1 >= 0) {
384 | val view = recycler.getViewForPosition(firstVisiblePosition - 1)
385 | resetViewAnimateProperty(view)
386 | removeAndRecycleView(view, recycler)
387 | }
388 | if (lastVisiblePosition + 1 < itemCount) {
389 | val view = recycler.getViewForPosition(lastVisiblePosition + 1)
390 | resetViewAnimateProperty(view)
391 | removeAndRecycleView(view, recycler)
392 | }
393 | }
394 |
395 | private fun resetViewAnimateProperty(view: View) {
396 | view.rotationY = 0f
397 | view.rotationX = 0f
398 | view.scaleX = 1f
399 | view.scaleY = 1f
400 | view.alpha = 1f
401 | }
402 |
403 | private fun calculateAndScrollToTarget(view: RecyclerView) {
404 | val targetPosition = calculateCenterPosition(getFirstVisibleItemPosition())
405 | scrollToCenter(targetPosition, view, true)
406 | }
407 |
408 | private fun scrollToCenter(targetPosition: Int, recyclerView: RecyclerView, animation: Boolean) {
409 | val targetOffset = getPositionOffset(targetPosition)
410 | when(mScrollOrientation) {
411 | ScrollOrientation.LEFT_TO_RIGHT, ScrollOrientation.RIGHT_TO_LEFT -> {
412 | if (animation) {
413 | recyclerView.smoothScrollBy(targetOffset - mScrollOffset, 0)
414 | } else {
415 | recyclerView.scrollBy(targetOffset - mScrollOffset, 0)
416 | }
417 | }
418 | else -> {
419 | if (animation) {
420 | recyclerView.smoothScrollBy(0, targetOffset - mScrollOffset)
421 | } else {
422 | recyclerView.scrollBy(0, targetOffset - mScrollOffset)
423 | }
424 | }
425 | }
426 | }
427 |
428 | private fun getValidOffset(expectOffset: Int): Int {
429 | return when(mScrollOrientation) {
430 | ScrollOrientation.RIGHT_TO_LEFT, ScrollOrientation.LEFT_TO_RIGHT -> Math.max(Math.min(width * (itemCount - 1), expectOffset), 0)
431 | else -> Math.max(Math.min(height * (itemCount - 1), expectOffset), 0)
432 | }
433 | }
434 |
435 | private fun getPositionOffset(position: Int): Int {
436 | return when(mScrollOrientation) {
437 | ScrollOrientation.RIGHT_TO_LEFT -> position * width
438 | ScrollOrientation.LEFT_TO_RIGHT -> (itemCount - 1 - position) * width
439 | ScrollOrientation.BOTTOM_TO_TOP -> position * height
440 | ScrollOrientation.TOP_TO_BOTTOM -> (itemCount - 1 - position) * height
441 | }
442 | }
443 |
444 | private fun getLastVisibleItemPosition(): Int {
445 | val firstVisiblePosition = getFirstVisibleItemPosition()
446 | return if (firstVisiblePosition + mVisibleItemCount > itemCount - 1) {
447 | itemCount - 1
448 | } else {
449 | firstVisiblePosition + mVisibleItemCount
450 | }
451 | }
452 |
453 | private fun getFirstVisibleItemMovePercent(): Float {
454 | if (width == 0 || height == 0) {
455 | return 0f
456 | }
457 | return when (mScrollOrientation) {
458 | ScrollOrientation.RIGHT_TO_LEFT -> (mScrollOffset % width) * 1.0f / width
459 | ScrollOrientation.LEFT_TO_RIGHT -> {
460 | val targetPercent = 1 - (mScrollOffset % width) * 1.0f / width
461 | return if (targetPercent == 1f) {
462 | 0f
463 | } else {
464 | targetPercent
465 | }
466 | }
467 | ScrollOrientation.BOTTOM_TO_TOP -> (mScrollOffset % height) * 1.0f / height
468 | ScrollOrientation.TOP_TO_BOTTOM -> {
469 | val targetPercent = 1 - (mScrollOffset % height) * 1.0f / height
470 | return if (targetPercent == 1f) {
471 | 0f
472 | } else {
473 | targetPercent
474 | }
475 | }
476 | }
477 | }
478 |
479 | private fun calculateCenterPosition(position: Int): Int {
480 | //当是 Fling 触发的时候
481 | val triggerOrientation = mFlingOrientation
482 | mFlingOrientation = FlingOrientation.NONE
483 | when(mScrollOrientation) {
484 | ScrollOrientation.RIGHT_TO_LEFT -> {
485 | if (triggerOrientation == FlingOrientation.RIGHT_TO_LEFT) {
486 | return position + 1
487 | } else if (triggerOrientation == FlingOrientation.LEFT_TO_RIGHT) {
488 | return position
489 | }
490 | }
491 | ScrollOrientation.LEFT_TO_RIGHT -> {
492 | if (triggerOrientation == FlingOrientation.LEFT_TO_RIGHT) {
493 | return position + 1
494 | } else if (triggerOrientation == FlingOrientation.RIGHT_TO_LEFT) {
495 | return position
496 | }
497 | }
498 | ScrollOrientation.BOTTOM_TO_TOP -> {
499 | if (triggerOrientation == FlingOrientation.BOTTOM_TO_TOP) {
500 | return position + 1
501 | } else if (triggerOrientation == FlingOrientation.TOP_TO_BOTTOM) {
502 | return position
503 | }
504 | }
505 | ScrollOrientation.TOP_TO_BOTTOM -> {
506 | if (triggerOrientation == FlingOrientation.TOP_TO_BOTTOM) {
507 | return position + 1
508 | } else if (triggerOrientation == FlingOrientation.BOTTOM_TO_TOP) {
509 | return position
510 | }
511 | }
512 | }
513 |
514 | //当不是 fling 触发的时候
515 | val percent = getFirstVisibleItemMovePercent()
516 | //向左移动超过50% position(firstVisibleItemPosition)++
517 | //否 position不变
518 | return if (percent < 0.5) {
519 | position
520 | } else {
521 | position + 1
522 | }
523 | }
524 | }
--------------------------------------------------------------------------------
/StackLayoutManager/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | StackLayoutManager
3 |
4 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.2.60'
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.4'
11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
12 | classpath 'com.novoda:bintray-release:0.8.1'
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | google()
19 | jcenter()
20 | }
21 | tasks.withType(Javadoc) {
22 | options{ encoding "UTF-8"
23 | charSet 'UTF-8'
24 | links "http://docs.oracle.com/javase/7/docs/api"
25 | }
26 | }
27 | }
28 |
29 | task clean(type: Delete) {
30 | delete rootProject.buildDir
31 | }
32 | tasks.getByPath(":StackLayoutManager:releaseAndroidJavadocs").enabled = false
33 |
--------------------------------------------------------------------------------
/gif/sample1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/gif/sample1.gif
--------------------------------------------------------------------------------
/gif/sample2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/gif/sample2.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 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jun 28 17:28:50 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/sample.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample.png
--------------------------------------------------------------------------------
/sample/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/.DS_Store
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion 27
9 | defaultConfig {
10 | applicationId "com.littlemango.stacklayoutmanagermaster"
11 | minSdkVersion 19
12 | targetSdkVersion 27
13 | versionCode 6
14 | versionName "1.0.5"
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | ext.kotlin_version = '1.2.60'
26 |
27 | dependencies {
28 | implementation fileTree(include: ['*.jar'], dir: 'libs')
29 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
30 | implementation 'com.android.support:appcompat-v7:27.1.1'
31 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
32 | testImplementation 'junit:junit:4.12'
33 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
34 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
35 | implementation 'com.android.support:recyclerview-v7:27.1.1'
36 | implementation 'com.android.support:cardview-v7:27.1.1'
37 | implementation project(':StackLayoutManager')
38 | implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
39 | implementation 'com.android.support:design:27.1.1'
40 | }
41 |
--------------------------------------------------------------------------------
/sample/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 |
--------------------------------------------------------------------------------
/sample/src/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/src/.DS_Store
--------------------------------------------------------------------------------
/sample/src/androidTest/java/com/littlemango/stacklayoutmanagermaster/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.littlemango.stacklayoutmanagermaster
2 |
3 | import android.support.test.InstrumentationRegistry
4 | import android.support.test.runner.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getTargetContext()
22 | assertEquals("com.littlemango.stacklayoutmanagermaster", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/sample/src/main/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/src/main/.DS_Store
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/littlemango/stacklayoutmanagermaster/FadeInFadeOutAnimation.java:
--------------------------------------------------------------------------------
1 | package com.littlemango.stacklayoutmanagermaster;
2 |
3 | import android.support.v7.widget.LinearLayoutManager;
4 | import android.view.View;
5 |
6 | import com.littlemango.stacklayoutmanager.StackAnimation;
7 | import com.littlemango.stacklayoutmanager.StackLayoutManager.ScrollOrientation;
8 |
9 | import org.jetbrains.annotations.NotNull;
10 |
11 | public class FadeInFadeOutAnimation extends StackAnimation {
12 |
13 | private int mVisibleCount;
14 |
15 | FadeInFadeOutAnimation(@NotNull ScrollOrientation scrollOrientation, int visibleCount) {
16 | super(scrollOrientation, visibleCount);
17 | mVisibleCount = visibleCount;
18 | }
19 |
20 | @Override
21 | public void doAnimation(float firstMovePercent, @NotNull View itemView, int position) {
22 | if (position == 0) {
23 | itemView.setAlpha(1 - firstMovePercent + 0.5f);
24 | } else if (position == mVisibleCount) {
25 | itemView.setAlpha(firstMovePercent);
26 | }
27 | itemView.setScaleX(1);
28 | itemView.setScaleY(1);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/littlemango/stacklayoutmanagermaster/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.littlemango.stacklayoutmanagermaster;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.util.Log;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.ImageView;
13 | import android.widget.TextView;
14 | import android.widget.Toast;
15 |
16 | import com.afollestad.materialdialogs.MaterialDialog;
17 | import com.littlemango.stacklayoutmanager.StackLayoutManager;
18 | import com.littlemango.stacklayoutmanager.StackLayoutManager.ScrollOrientation;
19 | import java.util.Random;
20 |
21 | public class MainActivity extends AppCompatActivity {
22 |
23 | private static final String TAG = "MainActivity";
24 | private RecyclerView mRecyclerView;
25 |
26 | private static final int mStackCount = 30;
27 |
28 | private int mRandomPosition;
29 |
30 | private StackLayoutManager mStackLayoutManager;
31 |
32 | private String[] selectItems;
33 |
34 | private Toast mToast;
35 |
36 | @Override
37 | protected void onCreate(@Nullable Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 | setContentView(R.layout.activity_main);
40 | mToast = Toast.makeText(MainActivity.this, "", Toast.LENGTH_SHORT);
41 | mRecyclerView = findViewById(R.id.recycleView);
42 |
43 | mStackLayoutManager = new StackLayoutManager();
44 | mRecyclerView.setLayoutManager(mStackLayoutManager);
45 | mRecyclerView.setAdapter(new StackLayoutAdapter());
46 |
47 | selectItems = getResources().getStringArray(R.array.items);
48 | resetRandom();
49 |
50 | findViewById(R.id.floatButton).setOnClickListener(new View.OnClickListener() {
51 | @Override
52 | public void onClick(View view) {
53 |
54 | new MaterialDialog.Builder(MainActivity.this)
55 | .items(selectItems)
56 | .itemsCallback(new MaterialDialog.ListCallback() {
57 | @Override
58 | public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
59 | switch (which) {
60 | case 0:
61 | mRecyclerView.smoothScrollToPosition(mRandomPosition);
62 | resetRandom();
63 | break;
64 | case 1:
65 | mRecyclerView.scrollToPosition(mRandomPosition);
66 | resetRandom();
67 | break;
68 | case 2:
69 | mStackLayoutManager = new StackLayoutManager(ScrollOrientation.LEFT_TO_RIGHT);
70 | mRecyclerView.setLayoutManager(mStackLayoutManager);
71 | getSupportActionBar().setTitle("Picture 0");
72 | break;
73 | case 3:
74 | mStackLayoutManager = new StackLayoutManager(ScrollOrientation.RIGHT_TO_LEFT);
75 | mRecyclerView.setLayoutManager(mStackLayoutManager);
76 | getSupportActionBar().setTitle("Picture 0");
77 | break;
78 | case 4:
79 | mStackLayoutManager = new StackLayoutManager(ScrollOrientation.TOP_TO_BOTTOM);
80 | mRecyclerView.setLayoutManager(mStackLayoutManager);
81 | getSupportActionBar().setTitle("Picture 0");
82 | break;
83 | case 5:
84 | mStackLayoutManager = new StackLayoutManager(ScrollOrientation.BOTTOM_TO_TOP);
85 | mRecyclerView.setLayoutManager(mStackLayoutManager);
86 | getSupportActionBar().setTitle("Picture 0");
87 | break;
88 | case 6:
89 | mStackLayoutManager.setPagerMode(!mStackLayoutManager.getPagerMode());
90 | break;
91 | case 7:
92 | mStackLayoutManager.setItemOffset(mStackLayoutManager.getItemOffset() + 10);
93 | mStackLayoutManager.requestLayout();
94 | break;
95 | case 8:
96 | mStackLayoutManager.setItemOffset(mStackLayoutManager.getItemOffset() - 10);
97 | mStackLayoutManager.requestLayout();
98 | break;
99 | case 9:
100 | mStackLayoutManager.setVisibleItemCount(mStackLayoutManager.getVisibleItemCount() + 1);
101 | mStackLayoutManager.requestLayout();
102 | break;
103 | case 10:
104 | mStackLayoutManager.setVisibleItemCount(mStackLayoutManager.getVisibleItemCount() - 1);
105 | mStackLayoutManager.requestLayout();
106 | break;
107 | case 11:
108 | mStackLayoutManager.setPagerFlingVelocity(mStackLayoutManager.getPagerFlingVelocity() + 5000);
109 | break;
110 | case 12:
111 | mStackLayoutManager.setPagerFlingVelocity(mStackLayoutManager.getPagerFlingVelocity() - 5000);
112 | break;
113 | case 13:
114 | mStackLayoutManager.setAnimation(new FadeInFadeOutAnimation(mStackLayoutManager.getScrollOrientation(),
115 | mStackLayoutManager.getVisibleItemCount()));
116 | mStackLayoutManager.requestLayout();
117 | break;
118 | }
119 |
120 | mStackLayoutManager.setItemChangedListener(new StackLayoutManager.ItemChangedListener() {
121 | @Override
122 | public void onItemChanged(int position) {
123 | getSupportActionBar().setTitle("Picture " + position);
124 | }
125 | });
126 | }
127 | })
128 | .show();
129 | }
130 | });
131 |
132 | mStackLayoutManager.setItemChangedListener(new StackLayoutManager.ItemChangedListener() {
133 | @Override
134 | public void onItemChanged(int position) {
135 | getSupportActionBar().setTitle("Picture " + position);
136 | }
137 | });
138 | }
139 |
140 | class StackLayoutAdapter extends RecyclerView.Adapter {
141 |
142 | @NonNull
143 | @Override
144 | public StackHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
145 |
146 | View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.image_card, viewGroup, false);
147 | return new StackHolder(view);
148 | }
149 |
150 | @Override
151 | public void onBindViewHolder(@NonNull final StackHolder stackHolder, int position) {
152 | int res;
153 | switch (position % 6) {
154 | case 0:
155 | res = R.drawable.image1;
156 | break;
157 | case 1:
158 | res = R.drawable.image2;
159 | break;
160 | case 2:
161 | res = R.drawable.image3;
162 | break;
163 | case 3:
164 | res = R.drawable.image4;
165 | break;
166 | case 4:
167 | res = R.drawable.image5;
168 | break;
169 | default:
170 | res = R.drawable.image6;
171 | break;
172 | }
173 | stackHolder.imageView.setImageResource(res);
174 | stackHolder.textView.setText("" + position);
175 | stackHolder.itemView.setOnClickListener(new View.OnClickListener() {
176 | @Override
177 | public void onClick(View v) {
178 | if (stackHolder.getAdapterPosition() == mStackLayoutManager.getFirstVisibleItemPosition()) {
179 | mToast.setText("position: " + stackHolder.getAdapterPosition() + " is click!");
180 | mToast.show();
181 | } else {
182 | mRecyclerView.smoothScrollToPosition(stackHolder.getAdapterPosition());
183 | }
184 | }
185 | });
186 | }
187 |
188 | @Override
189 | public int getItemCount() {
190 | return mStackCount;
191 | }
192 |
193 | class StackHolder extends RecyclerView.ViewHolder {
194 | View itemView;
195 | ImageView imageView;
196 | TextView textView;
197 |
198 | StackHolder(@NonNull View itemView) {
199 | super(itemView);
200 | this.itemView = itemView;
201 | imageView = itemView.findViewById(R.id.imageView);
202 | textView = itemView.findViewById(R.id.textView);
203 | }
204 | }
205 | }
206 |
207 | private void resetRandom() {
208 | mRandomPosition = Math.abs(new Random().nextInt() % mStackCount);
209 | selectItems[0] = getResources().getString(R.string.smooth_scroll) + mRandomPosition;
210 | selectItems[1] = getResources().getString(R.string.scroll) + mRandomPosition;
211 | }
212 | }
213 |
--------------------------------------------------------------------------------
/sample/src/main/res/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/src/main/res/.DS_Store
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/sample/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 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/ic_star_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/image1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/src/main/res/drawable/image1.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/image2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/src/main/res/drawable/image2.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/image3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/src/main/res/drawable/image3.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/image4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/src/main/res/drawable/image4.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/image5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/src/main/res/drawable/image5.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/image6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/src/main/res/drawable/image6.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
24 |
25 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/image_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
14 |
15 |
20 |
21 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LittleMango/StackLayoutManager/334e6d26bde127f39c7fc506bc639d3bf3bab76e/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/values-zh-rCN/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 | -
6 | - 卡片从左到右移出
7 | - 卡片从右到左移出
8 | - 卡片从上到下移出
9 | - 卡片从下到上移出
10 | - 改变PageMode
11 | - 增加每个item之间的偏移
12 | - 减少每个item之间的偏移
13 | - 增加可见item的数量
14 | - 减少可见item的数量
15 | - 增加PageMode=true时的滑动阻尼
16 | - 减少PageMode=true时的滑动阻尼
17 | - 自定义动画
18 |
19 |
--------------------------------------------------------------------------------
/sample/src/main/res/values-zh-rCN/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | StackLayoutManagerMaster
3 | 带动画滚动到指定位置
4 | 不带动画滚动到指定位置
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 | -
6 | - From Left To Right
7 | - From Right To Left
8 | - From Top To Bottom
9 | - From Bottom To Top
10 | - Change PageMode
11 | - Increase item offset
12 | - Decrease item offset
13 | - Increase visible itemCount
14 | - Decrease visible itemCount
15 | - Increase fling damp
16 | - Decrease fling damp
17 | - Use custom animation
18 |
19 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | StackLayoutManagerMaster
3 | smoothScroll to
4 | scroll to
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/sample/src/test/java/com/littlemango/stacklayoutmanagermaster/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.littlemango.stacklayoutmanagermaster
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample', ':StackLayoutManager'
2 |
--------------------------------------------------------------------------------