繁体   English   中英

如何在不复制和粘贴其父 onMeasure 实现的情况下修改自定义 TextView WRAP_CONTENT 高度?

[英]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 进行转换。)

请参阅View#setMeasuredDimension

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM