美文网首页
Android View 从下往上进入,从上往下退出动画

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

作者: _发强 | 来源:发表于2022-04-17 01:05 被阅读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>
    

    相关文章

      网友评论

          本文标题:Android View 从下往上进入,从上往下退出动画

          本文链接:https://www.haomeiwen.com/subject/jfpkertx.html