feat: home
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package com.yuanxuan.rokid.extension
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.util.TypedValue
|
||||
|
||||
fun Number.dpToPx(): Float {
|
||||
return TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP,
|
||||
this.toFloat(),
|
||||
Resources.getSystem().displayMetrics
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.yuanxuan.rokid.extension
|
||||
|
||||
import android.animation.Animator
|
||||
import android.animation.AnimatorListenerAdapter
|
||||
import android.view.View
|
||||
import androidx.core.view.isGone
|
||||
import androidx.core.view.isVisible
|
||||
|
||||
|
||||
fun View.animateTranslationY(translationY: Float, duration: Int) {
|
||||
animate()
|
||||
.translationY(translationY)
|
||||
.setDuration(250)
|
||||
.start()
|
||||
}
|
||||
|
||||
fun View.fadeIn(duration: Long) {
|
||||
if (this.isVisible) return
|
||||
this.alpha = 0f
|
||||
this.isVisible = true
|
||||
this.animate()
|
||||
.alpha(1f)
|
||||
.setDuration(duration)
|
||||
.setListener(null)
|
||||
}
|
||||
|
||||
fun View.fadeOut(duration: Long) {
|
||||
if (this.isVisible.not()) return
|
||||
this.animate()
|
||||
.alpha(0f)
|
||||
.setDuration(duration)
|
||||
.setListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
this@fadeOut.isGone = true
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user