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

本文标签: