AnimUtils.kt 1.63 KB
Newer Older
1
package com.ydl.ydlcommon.utils
konghaorui committed
2 3

import android.view.View
4
import android.view.animation.AccelerateInterpolator
konghaorui committed
5 6 7
import android.view.animation.Animation
import android.view.animation.TranslateAnimation

8

konghaorui committed
9 10 11 12 13 14 15 16 17
/**
 * @author yuanWai
 * @描述:
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2019/2/19
 */
class AnimUtils {
    companion object {
18 19 20 21 22 23
        fun slideToUp(view: View) {
            val slide = TranslateAnimation(
                Animation.RELATIVE_TO_SELF, 0.0f,
                Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
                1.0f, Animation.RELATIVE_TO_SELF, 0.0f
            )
konghaorui committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
            slide.duration = 400
            slide.fillAfter = true
            slide.isFillEnabled = true
            view.startAnimation(slide)
            slide.setAnimationListener(object : Animation.AnimationListener {
                override fun onAnimationRepeat(animation: Animation?) {

                }

                override fun onAnimationEnd(animation: Animation?) {

                }

                override fun onAnimationStart(animation: Animation?) {

                }
            })
        }
42 43 44 45 46 47 48 49 50 51 52 53

        fun slideToDown(view: View?) {
            val animation = TranslateAnimation(
                Animation.RELATIVE_TO_SELF, 0F, Animation.RELATIVE_TO_SELF, 0f,
                Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0F
            )
            animation.duration = 400
            animation.repeatMode = Animation.REVERSE
            animation.interpolator = AccelerateInterpolator()
            animation.fillAfter = true
            view?.startAnimation(animation)
        }
konghaorui committed
54 55
    }
}