marginInfo 未设置时,addHighLight 未添加进去,导致显示时 crash #80
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
报错日志如下:
我的高亮提示场景是不需要给高亮 View 扣矩形,且提示 View 需要在屏幕的顶部,添加高亮提示 View 的代码如下:
marginInfo 只设置了 top 的值,正常情况下,top 的值是状态栏的高度,此时 marginInfo 里是有值的,高亮 View 可以正常显示;当使用鸿蒙平板的小窗模式后,因为小窗脱离状态栏了,所以 top 值就成 0 了,此时 marginInfo 里的值都为 0,在调用
HighLight.show()
后,之后的调用链会走到HighLightView.addViewForEveryTip()
,这个方法中因为 marginInfo 都是 0,所以这里LayoutParams
会返回 null,直接 return 了,没添加上高亮布局,导致现实的时候 crash 了:以上调用链,注释中解释了 crash 的原因。
我的解决方案是,在
addViewForEveryTip
中,不再调用buildTipLayoutParams
方法,去掉 null 的判断,直接把 marginInfo 的值赋给 LayoutParams,保证addView
可以调用到: