-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use with custom PageTransformer #36
Comments
After some investigation, I think there are some problems with PageTransformer and ViewPager's Currently, I cannot find a solution, but in the future I will change it to base on |
Actually I think the sample implementation of PageTransformer assumes a very simple use case without thinking the case of For example, if I change the code of private const val MIN_SCALE = 0.85f
private const val MIN_ALPHA = 0.5f
class ZoomOutPageTransformer : ViewPager.PageTransformer {
override fun transformPage(view: View, position: Float) {
view.apply {
val pageWidth = width
val pageHeight = height
when {
position < -1 -> { // [-Infinity,-1)
// This page is way off-screen to the left.
reset(view)
}
position <= 1 -> { // [-1,1]
// Modify the default slide transition to shrink the page as well
val scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position))
val vertMargin = pageHeight * (1 - scaleFactor) / 2
val horzMargin = pageWidth * (1 - scaleFactor) / 2
translationX = if (position < 0) {
horzMargin - vertMargin / 2
} else {
horzMargin + vertMargin / 2
}
// Scale the page down (between MIN_SCALE and 1)
scaleX = scaleFactor
scaleY = scaleFactor
// Fade the page relative to its size.
alpha = (MIN_ALPHA +
(((scaleFactor - MIN_SCALE) / (1 - MIN_SCALE)) * (1 - MIN_ALPHA)))
}
else -> { // (1,+Infinity]
// This page is way off-screen to the right.
reset(view)
}
}
}
}
private fun reset(view: View) {
view.apply {
alpha = 1f
translationX = 0f
scaleX = 1f
scaleY = 1f
}
}
} Though there are still problems - I can somehow peek the left item when scrolling backward. So I think may be the problem lies in the incomplete implementation of the PageTransformer. Therefore before going ahead, I think I need to understand how to implement |
Hi Sira,
I"m trying to use your library with a custom PageTransformer (https://developer.android.com/training/animation/screen-slide).
The trick used for infinite scroll (smoothScroll: false) and custom transition seem to conflict. The content disappears for a short time during the last > first flip.
Do you have any idea how to solve this problem?
Thanks and regards,
Csanad
The text was updated successfully, but these errors were encountered: