diff --git a/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/DefaultAnimation.kt b/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/DefaultAnimation.kt index 9742e9e..d8b0b81 100644 --- a/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/DefaultAnimation.kt +++ b/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/DefaultAnimation.kt @@ -2,6 +2,7 @@ package com.littlemango.stacklayoutmanager import android.view.View import com.littlemango.stacklayoutmanager.StackLayoutManager.ScrollOrientation +import kotlin.math.pow class DefaultAnimation(scrollOrientation: ScrollOrientation, visibleCount: Int) : StackAnimation(scrollOrientation, visibleCount) { @@ -72,8 +73,8 @@ class DefaultAnimation(scrollOrientation: ScrollOrientation, visibleCount: Int) scale = 1 - ((1 - mOutScale) * firstMovePercent) rotation = mOutRotation * firstMovePercent } else { - val minScale = (Math.pow(mScale.toDouble(), position.toDouble())).toFloat() - val maxScale = (Math.pow(mScale.toDouble(), (position - 1).toDouble())).toFloat() + val minScale = (mScale.toDouble().pow(position.toDouble())).toFloat() + val maxScale = (mScale.toDouble().pow((position - 1).toDouble())).toFloat() scale = minScale + (maxScale - minScale) * firstMovePercent //只对最后一个 item 做透明度变化 if (position == mVisibleCount) { diff --git a/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/StackLayoutManager.kt b/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/StackLayoutManager.kt index 5eef721..5c5ae25 100644 --- a/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/StackLayoutManager.kt +++ b/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/StackLayoutManager.kt @@ -6,6 +6,8 @@ import android.support.v7.widget.RecyclerView.SCROLL_STATE_DRAGGING import android.support.v7.widget.RecyclerView.SCROLL_STATE_IDLE import android.view.View import android.view.ViewGroup +import kotlin.math.max +import kotlin.math.min class StackLayoutManager(scrollOrientation: ScrollOrientation, visibleCount: Int, @@ -427,8 +429,8 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation, private fun getValidOffset(expectOffset: Int): Int { return when(mScrollOrientation) { - ScrollOrientation.RIGHT_TO_LEFT, ScrollOrientation.LEFT_TO_RIGHT -> Math.max(Math.min(width * (itemCount - 1), expectOffset), 0) - else -> Math.max(Math.min(height * (itemCount - 1), expectOffset), 0) + ScrollOrientation.RIGHT_TO_LEFT, ScrollOrientation.LEFT_TO_RIGHT -> max(min(width * (itemCount - 1), expectOffset), 0) + else -> max(min(height * (itemCount - 1), expectOffset), 0) } }