近段时间的学习碎片整理(28)

1、回调写法


interface TestListener {
        fun click1()
        fun click2()
    }

 private var testListener: TestListener? = null
        fun setForTestListener(listener: TestListener) {
            testListener = listener
        }
tvSaveMoon.noFastClick {
//在需要回调的地方,写上对应的方法
                testListener?.click1()
               
}

2、属性动画(最近有需求需要完成一个类似椭圆的动画),研究了一下,做一下记录


private val animatorSet by lazy {
        AnimatorSet()
    }
    private val firstPoint = IntArray(2) //动画开始点
    private val endPoint = IntArray(2) //动画结束点
    private val parentLocation = IntArray(2) //弧线图点
    private val translationX by lazy {
        ObjectAnimator.ofFloat(binding.ivAnimationMoon, "translationX", 0f, endPoint[0].toFloat() - firstPoint[0])
    }
 binding.ivTest.post {
            //需要在视图加载成功后才能获取到坐标点
            binding.ivAnimation1.getLocationInWindow(firstPoint)
            binding.ivAnimationMoon2.getLocationInWindow(endPoint)
            binding.ivAnimationCircle.getLocationInWindow(parentLocation)

            translationX.interpolator = LinearInterpolator()

            val translationY =
                ObjectAnimator.ofFloat(binding.ivAnimationMoon,
                    "translationY",0f,
                    parentLocation[1].toFloat() - firstPoint[1] - (binding.ivAnimationMoon.height / 2), 0f)
            translationY.interpolator = TimeInterpolator { input ->
                (0.5f * sin(Math.PI * input)).toFloat()
            }
            animatorSet.playTogether(translationX, translationY)
            animatorSet.duration = 1000
 }


 if (animatorSet.isRunning) {
            animatorSet.cancel()
        }
        val target = (endPoint[0].toFloat() - firstPoint[0]) * percent
        translationX.removeAllUpdateListeners()
        translationX.addUpdateListener {
            val value = it.animatedValue as Float
            if (value >= target) {
                animatorSet.cancel()
            }
        }
        animatorSet.start()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值