animation - How to Set Height Width Automatically When Focus on ItemView in Recyclerview in Android? - Stack Overflow

i have try setOnFoucsChangeListner for Itemview in Recyclerview in ViewHolderbinding.image.setOnFocusCh

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744253114a4565261.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信