File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed
lib/src/main/java/com/example/lib Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -57,9 +57,7 @@ class Deck : ViewPager {
57
57
percentage < 0 -> throw IllegalArgumentException (" Percentage can't be lower than 0" )
58
58
percentage >= 50 -> throw IllegalArgumentException (" Your layout will not visible if the percentage equals or higher than 50" )
59
59
else -> {
60
- val metrics = DisplayMetrics ()
61
- (context as Activity ).windowManager.defaultDisplay.getMetrics(metrics)
62
- val padding = metrics.widthPixels * percentage / 100f
60
+ val padding = screenWidth(context) * percentage / 100f
63
61
initProperties(context, padding)
64
62
}
65
63
}
@@ -83,8 +81,12 @@ class Deck : ViewPager {
83
81
clipToPadding = false
84
82
pageMargin = 0
85
83
84
+ pageTransformer.paddingFactor = padding / screenWidth(context)
85
+ }
86
+
87
+ private fun screenWidth (context : Context ): Int {
86
88
val metrics = DisplayMetrics ()
87
89
(context as Activity ).windowManager.defaultDisplay.getMetrics(metrics)
88
- pageTransformer.paddingFactor = padding / metrics.widthPixels
90
+ return metrics.widthPixels
89
91
}
90
92
}
You can’t perform that action at this time.
0 commit comments