admin管理员组文章数量:1400420
i have try setOnFoucsChangeListner for Itemview in Recyclerview in ViewHolder
binding.image.setOnFocusChangeListener { v, hasFocus ->
manageFocusAnimation(hasFocus, recyclerview)
}
private fun manageFocusAnimation(hasFocus: Boolean, recyclerview: RecyclerView) {
val startWidth = binding.image.width
val endWidth = if (hasFocus) dpToPx(465) else dpToPx(175)
val endWidthShadow = if (hasFocus) dpToPx(478) else dpToPx(168)
val valueAnimator = ValueAnimator.ofInt(startWidth, endWidth)
valueAnimator.duration = 50
valueAnimator.interpolator = AccelerateDecelerateInterpolator()
val layoutParams = binding.image.layoutParams
valueAnimator.addUpdateListener { animator ->
layoutParams.width = animator.animatedValue as Int
binding.image.layoutParams = layoutParams
}
valueAnimator.start()
val valueAnimatorShadow = ValueAnimator.ofInt(startWidth, endWidthShadow)
valueAnimatorShadow.duration = 50
valueAnimatorShadow.interpolator = AccelerateDecelerateInterpolator()
val layoutParamsShadow = binding.shadow.layoutParams
valueAnimatorShadow.addUpdateListener { animator ->
layoutParamsShadow.width = animator.animatedValue as Int
binding.shadow.layoutParams = layoutParamsShadow
}
valueAnimatorShadow.start()
valueAnimator.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
if (hasFocus) {
binding.shadow.isVisible = true
setDefaultMargin()
recyclerview.scrollToPositionWithOffset(position, 0)
} else {
binding.shadow.isVisible = false
}
}
})
}
private fun setDefaultMargin() {
val newLayoutParams = itemView.layoutParams as ViewGroup.MarginLayoutParams
newLayoutParams.setMargins(10, 0, 10, 0)
itemView.layoutParams = newLayoutParams
}
}````
this is the above code for set Height width for Itemview with ValueAnimation of It does not affect the to real item please help me to solve this issue
i have try above code but this code is not solving my issue i want to change width of itemview on Foucs itemview please if anybody know to to do it give me hint or solutions
本文标签:
版权声明:本文标题:animation - How to Set Height Width Automatically When Focus on ItemView in Recyclerview in Android? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744253113a2597343.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论