我正在尝试创建一个可扩展/可折叠CardView
(根布局),我将动态添加到垂直LinearLayout(父布局),特别是TextInputLayouts。添加视图后,我想调整动画大小,以适应新添加的视图。我在做的是:
removeAllViews()
addView()
计算新高度:
val previousMeasuredHeight = parentLayout.measuredHeight
parentLayout.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
将父布局设置为新高度:
val animator = ValueAnimator.ofInt(previousMeasuredHeight, measuredHeight)
animator.addUpdateListener { valueAnimator ->
layoutParams.height = valueAnimator.animatedValue as Int
setLayoutParams(layoutParams)
}
animator.start()
我面临两个问题:
getMeasuredHeight()
而不是正确的方法计算总所需高度我还尝试使用RecyclerView
,但也有一些问题,例如添加项目时未显示,或者父版面没有正确调整大小
如何解决这些问题?