![](/img/trans.png)
[英]How to set wrap_content with min height on view OnMeasure?
[英]How to modify a custom TextView WRAP_CONTENT height without copying and pasting its parent onMeasure implementation?
我正在创建一个自定义TextView
并且我想知道是否可以在不复制和粘贴其父onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)
实现的情况下修改WRAP_CONTENT
高度的结果计算。
假设我的WRAP_CONTENT
计算等于父母的结果计算 + 16dp
。
在您的自定义视图中,让 super 完成其工作,然后修改结果:
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
setMeasuredDimension(measuredWidth,measuredHeight + 16)
}
(这里 16 是 16px,所以如果你想要的话,你必须为 16dp 进行转换。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.