|
@@ -4,6 +4,7 @@ import android.os.Build
|
|
|
import android.view.View
|
|
|
import androidx.annotation.RequiresApi
|
|
|
import androidx.viewpager2.widget.ViewPager2
|
|
|
+import com.zhpan.indicator.utils.IndicatorUtils
|
|
|
import kotlin.math.abs
|
|
|
import kotlin.math.max
|
|
|
|
|
@@ -13,11 +14,11 @@ import kotlin.math.max
|
|
|
*/
|
|
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
|
|
class OverlapPageTransformer(
|
|
|
- private val orientation: Int,
|
|
|
- private val minScale: Float = 0f,
|
|
|
- private val unSelectedItemRotation: Float = 0f,
|
|
|
- private val unSelectedItemAlpha: Float = 0f,
|
|
|
- private val itemGap: Float = 0f
|
|
|
+ private val orientation: Int,
|
|
|
+ private val minScale: Float = 0f,
|
|
|
+ private val unSelectedItemRotation: Float = 0f,
|
|
|
+ private val unSelectedItemAlpha: Float = 0f,
|
|
|
+ private val itemGap: Float = 0f
|
|
|
) : ViewPager2.PageTransformer {
|
|
|
|
|
|
init {
|
|
@@ -35,7 +36,7 @@ class OverlapPageTransformer(
|
|
|
|
|
|
if (unSelectedItemRotation != 0f) {
|
|
|
val rotation =
|
|
|
- (1 - delta) * if (position > 0) unSelectedItemRotation else -unSelectedItemRotation
|
|
|
+ (1 - delta) * if (position > 0) unSelectedItemRotation else -unSelectedItemRotation
|
|
|
|
|
|
rotationY = rotation
|
|
|
}
|
|
@@ -46,18 +47,19 @@ class OverlapPageTransformer(
|
|
|
scaleX = scale
|
|
|
scaleY = scale
|
|
|
|
|
|
+ val dp2px = IndicatorUtils.dp2px((itemGap.toInt() / 2).toFloat())
|
|
|
when (orientation) {
|
|
|
ViewPager2.ORIENTATION_HORIZONTAL -> {
|
|
|
translationX =
|
|
|
- position * (itemGap.toInt() / 2).toPx() +
|
|
|
- if (position > 0) {
|
|
|
- (-width * (1f - scale))
|
|
|
- } else {
|
|
|
- (width * (1f - scale))
|
|
|
- }
|
|
|
+ position * dp2px +
|
|
|
+ if (position > 0) {
|
|
|
+ (-width * (1f - scale))
|
|
|
+ } else {
|
|
|
+ (width * (1f - scale))
|
|
|
+ }
|
|
|
}
|
|
|
ViewPager2.ORIENTATION_VERTICAL -> {
|
|
|
- translationY = position * (itemGap.toInt()).toPx() +
|
|
|
+ translationY = position * dp2px +
|
|
|
if (position > 0) {
|
|
|
(-width * (1f - scale))
|
|
|
} else {
|