lybeat/PlumbTextView

测量问题 About measuring problems

Opened this issue · 5 comments

假如高度为0,出现错误。(除于0了)。例如RelativeLayout中使用,需要多次测量的情况下。
If the height is 0, there is an error. (Divided by 0). For example, the use of RelativeLayout, the need for multiple measurements.

3Q.的确会出现这个问题呢!我会在之后的版本修改的。

遇到了同样的问题!

遇到了同样问题,请问有解决了吗?

问题在于 onMeasure 时没有考虑 MeasureSpec.UNSPECIFIED 的情况,直接修改 onMeasure 中几行代码即可:

1. 测量 height 的代码

if (height > heightSize) {
height = heightSize;
}

改为:

if (heightMode == MeasureSpec.AT_MOST
        && height > heightSize) {
    height = heightSize;
}

2. 测量 width 的代码

if (width > widthSize && widthSize > 0) {
width = widthSize;
}

改为:

if (widthMode == MeasureSpec.AT_MOST
        && width > widthSize) {
    width = widthSize;
}

问题在于onMeasure时没有考虑MeasureSpec.UNSPECIFIED的情况,直接修改onMeasure中几行代码即可:

1.测量身高的代码

if (height > heightSize) {
height = heightSize;
}

改为:

如果(heightMode ==  MeasureSpecAT_MOST 
        &&高度> heightSize){
    height = heightSize;
}

2.测量宽度的代码

if (width > widthSize && widthSize > 0) {
width = widthSize;
}

改为:

如果(widthMode ==  MeasureSpecAT_MOST 
        &&宽度> widthSize){
    width = widthSize;
}

还是不行,divide by zero