![](/img/trans.png)
[英]Using MountSpec component with “wrap_content” View - How to implement onMeasure()
[英]How to set wrap_content with min height on view OnMeasure?
我为延伸按钮的视图设置了最小高度
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int h = resolveSize(minHeight, heightMeasureSpec);
if (h < minHeight) h = minHeight;
setMeasuredDimension(widthMeasureSpec, h);
rectBG.set(0, 0, MeasureSpec.getSize(widthMeasureSpec), h);
mBgPaint.setShader(
new LinearGradient(0, 0, 0, rectBG.bottom, colorStart, colorEnd, Shader.TileMode.MIRROR));
}
但是当我设置大文本时,我的视图不会扩展。 如何处理?
问题是您调用了super.onMeasure(widthMeasureSpec, heightMeasureSpec)
,然后尝试执行计算。
您应该依靠调用super.onMeasure(widthMeasureSpec, heightMeasureSpec)
或使用setMeasuredDimension
。
除非您的View
出现其他问题,否则删除super
调用应该可以解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.