短视频代码,自定义叠加动画

2021-01-26 14:57:07 浏览数 (1)

短视频代码,自定义叠加动画实现的相关代码

代码语言:javascript复制
package im.zebra.myviewpager2
import android.view.View
import androidx.viewpager2.widget.ViewPager2
import kotlin.math.abs
private const val MIN_SCALE = 1f
class ViewPagerOverlay : ViewPager2.PageTransformer {
    override fun transformPage(view: View, position: Float) {
        val pageWidth = view.width
        when {
            position < -1 -> { // [-Infinity,-1)
                // This page is way off-screen to the left.
                view.alpha = 0f
            }
            position <= 0 -> { // [-1,0]
                // Use the default slide transition when moving to the left page
                view.alpha = 1F
                view.translationX = 0f
                view.scaleX = 1f
                view.scaleY = 1f
            }
            position <= 1 -> { // (0,1]
                // Fade the page out.
                view.alpha = 1 - position
                // Counteract the default slide transition
                view.translationX = pageWidth * -position
                // Scale the page down (between MIN_SCALE and 1)
                val scaleFactor: Float = (MIN_SCALE
                          (1 - MIN_SCALE) * (1 - abs(position)))
                view.scaleX = scaleFactor
                view.scaleY = scaleFactor
            }
            else -> { // (1, Infinity]
                // This page is way off-screen to the right.
                view.alpha = 0f
            }
        }
    }
}

以上就是 短视频代码,自定义叠加动画实现的相关代码,更多内容欢迎关注之后的文章

0 人点赞