Android View 从下往上进入,从上往下退出动画

2022-04-17  本文已影响0人  _发强

View show 从下往上展示

    fun show() {
        val anim = AnimationUtils.loadAnimation(context, R.anim.slide_in_down)
        anim.setAnimationListener(object : Animation.AnimationListener {
            override fun onAnimationStart(animation: Animation?) {
            }

            override fun onAnimationEnd(animation: Animation?) {
            }

            override fun onAnimationRepeat(animation: Animation?) {
            }

        })
        this.startAnimation(anim)
        this.visible()
    }

slide_in_down 文件实现:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromYDelta="100%p" android:toYDelta="0" android:duration="350"/>
    <!--<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="350" />-->
</set>

View 从上往下退出:

    fun dismiss() {
        val anim = AnimationUtils.loadAnimation(context, R.anim.slide_out_down)
        anim.setAnimationListener(object : Animation.AnimationListener {
            override fun onAnimationStart(animation: Animation?) {
            }

            override fun onAnimationEnd(animation: Animation?) {
                this@SelfView.gone()
            }

            override fun onAnimationRepeat(animation: Animation?) {
            }
        })

        this.startAnimation(anim)
    }

slide_out_down 文件实现:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromYDelta="0" android:toYDelta="100%p" android:duration="350"/>
    <!--<alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="350" />-->
</set>
上一篇下一篇

猜你喜欢

热点阅读