2025-12-26 07:42:25 +00:00
|
|
|
package com.gamedog.vididin.widget
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.animation.AnimatorSet
|
|
|
|
|
import android.animation.ObjectAnimator
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.util.AttributeSet
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
|
import android.widget.LinearLayout
|
|
|
|
|
import com.ama.core.architecture.util.ResUtil.dp
|
2025-12-31 07:11:21 +00:00
|
|
|
import com.viddin.videos.free.databinding.LayoutAnimImageviewBinding
|
2025-12-26 08:48:37 +00:00
|
|
|
|
2025-12-26 07:42:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class AnimImageView @JvmOverloads constructor(
|
|
|
|
|
context: Context,
|
|
|
|
|
attrs: AttributeSet? = null,
|
|
|
|
|
defStyleAttr: Int = 0
|
|
|
|
|
) : LinearLayout(context, attrs, defStyleAttr) {
|
|
|
|
|
private var mBinding: LayoutAnimImageviewBinding
|
|
|
|
|
private val animationFraction = 0.2f
|
|
|
|
|
private var animatorSet: AnimatorSet = AnimatorSet()
|
|
|
|
|
|
|
|
|
|
init {
|
|
|
|
|
mBinding = LayoutAnimImageviewBinding.inflate(LayoutInflater.from(context), this, true)
|
|
|
|
|
startAnim()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun startAnim() {
|
|
|
|
|
with(mBinding) {
|
|
|
|
|
// 1. move distance
|
|
|
|
|
/*val moveDistanceX = -min(ivImage.width, ivImage.height) * animationFraction
|
|
|
|
|
val moveDistanceY = -min(ivImage.width, ivImage.height) * animationFraction*/
|
|
|
|
|
val moveDistanceX = -20.dp
|
|
|
|
|
val moveDistanceY = -20.dp
|
|
|
|
|
|
|
|
|
|
// 2. x and y
|
|
|
|
|
val animatorX = ObjectAnimator.ofFloat(ivImage, "translationX", 0f, moveDistanceX.toFloat())
|
|
|
|
|
val animatorY = ObjectAnimator.ofFloat(ivImage, "translationY", 0f, moveDistanceY.toFloat())
|
|
|
|
|
animatorX.repeatMode = ObjectAnimator.REVERSE
|
|
|
|
|
animatorX.repeatCount = ObjectAnimator.INFINITE
|
|
|
|
|
animatorY.repeatMode = ObjectAnimator.REVERSE
|
|
|
|
|
animatorY.repeatCount = ObjectAnimator.INFINITE
|
|
|
|
|
|
|
|
|
|
// 3. set
|
|
|
|
|
animatorSet.playTogether(animatorX, animatorY)
|
|
|
|
|
animatorSet.duration = 600
|
|
|
|
|
|
|
|
|
|
animatorSet.start()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onDetachedFromWindow() {
|
|
|
|
|
super.onDetachedFromWindow()
|
|
|
|
|
animatorSet.cancel()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|