Prince
Prince

Reputation: 1

Animation measure() function is not calculating full height issue

The measure() function is not calculating the correct height on the first click, which is causing the full height issue. The RecyclerView is getting an incorrect height on the first click, but after clicking again, it calculates enter image description here

i need to same height every time and smooth animation Once the correct height is measured

binding.icPlusMenu.setOnClickListener {

            if (isSubMenuExpanded) {
                val initialHeight = binding.rvDrawerSubmenu.measuredHeight
                val animation = ValueAnimator.ofInt(initialHeight, 0).apply {
                    duration = 300
                    addUpdateListener { valueAnimator ->
                        binding.rvDrawerSubmenu.layoutParams.height =
                            valueAnimator.animatedValue as Int
                        binding.rvDrawerSubmenu.requestLayout()
                    }
                    doOnEnd { binding.rvDrawerSubmenu.visibility = View.GONE }
                }
                animation.start()
                binding.rvDrawerSubmenu.animate().alpha(0f).setDuration(300).start()
                binding.icPlusMenu.animate().rotation(0f).setDuration(300).start()
                binding.icPlusMenu.setImageResource(R.drawable.ic_plus)
            } else {
                binding.rvDrawerSubmenu.visibility = View.VISIBLE
// i think else me problem he 
                binding.rvDrawerSubmenu.measure(0,0)
                val targetHeight = binding.rvDrawerSubmenu.measuredHeight
                binding.rvDrawerSubmenu.layoutParams.height = 0
                val anim = ValueAnimator.ofInt(0, targetHeight).apply {
                    duration = 300
                    addUpdateListener { animation ->
                        binding.rvDrawerSubmenu.layoutParams.height =
                            animation.animatedValue as Int
                        binding.rvDrawerSubmenu.requestLayout()
                    }
                }

                anim.start()
                binding.rvDrawerSubmenu.animate().alpha(1f).setDuration(300).start()
                binding.icPlusMenu.animate().rotation(180f).setDuration(300).start()
                binding.icPlusMenu.setImageResource(R.drawable.ic_minus)
            }
            isSubMenuExpanded = !isSubMenuExpanded
        }

Upvotes: 0

Views: 10

Answers (0)

Related Questions