Procházet zdrojové kódy

Merge remote-tracking branch 'origin/master'

zhpanvip před 4 roky
rodič
revize
fcb6d6b231

+ 0 - 12
bannerview/src/main/java/com/zhpan/bannerview/transform/Extensions.kt

@@ -1,12 +0,0 @@
-package com.zhpan.bannerview.transform
-
-import android.content.res.Resources
-
-fun Int.toDp(): Int = (this / Resources.getSystem().displayMetrics.density).toInt()
-fun Int.toPx(): Int = (this * Resources.getSystem().displayMetrics.density).toInt()
-
-fun Float.cube(): Float = this * this * this
-fun Int.cube(): Int = this * this * this
-
-fun Float.sqr(): Float = this * this
-fun Int.sqr(): Int = this * this

+ 15 - 13
bannerview/src/main/java/com/zhpan/bannerview/transform/OverlapPageTransformer.kt

@@ -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 {