var expand = true//记录当前是折叠还是展开状态
var viewHeight: Int = 0//记录控件的原始高度
fun expand(view: View) {
expand = true
tv_fold.text = "收起"
iv_fold.setImageResource(R.drawable.icon_con_shouqi_gray)
view.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
if (viewHeight < 152) {
return
}
view.layoutParams.height = viewHeight
view.requestLayout()
}
fun collapse(view: View) {
expand = false
tv_fold.text = "展开"
iv_fold.setImageResource(R.drawable.icon_con_zhankai_gray)
view.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
viewHeight = view.layoutParams.height
if (viewHeight < 152) {
return
}
view.layoutParams.height = 152
view.requestLayout()
}
Android开发 内容的折叠与展开
最新推荐文章于 2024-06-19 03:27:48 发布