在硬件加速设置为 false 的自定义视图中获取 canvas 大小
Get canvas size in custom view with hardwareAcceleration set to false
当我在 AndroidManifest.xml
和 hardwareAccelerated="false"
中将硬件加速设置为 false
时,方法 canvas.getWidth()
或 canvas.getHeight()
回落到一个奇怪的行为:
@Override
protected void onDraw(Canvas canvas) {
int h = canvas.getHeight();
int w = canvas.getWidth();
}
如果开启:h
= 视图高度 & w
= 视图宽度(例如 500x500)
如果硬件加速关闭:h
= 屏幕高度 & w
= 屏幕宽度(例如 1080x1920)
当 hardwareAcceleration
为 false
时,如何获取视图的尺寸?
How can I get the dimensions of my view when hardwareAcceleration
is false
?
Canvas尺寸与View
尺寸无关。如果您想获得 onDraw()
内视图的大小,您可以使用 getMeasuredWidth()
/getMeasuredHeight()
.
当我在 AndroidManifest.xml
和 hardwareAccelerated="false"
中将硬件加速设置为 false
时,方法 canvas.getWidth()
或 canvas.getHeight()
回落到一个奇怪的行为:
@Override
protected void onDraw(Canvas canvas) {
int h = canvas.getHeight();
int w = canvas.getWidth();
}
如果开启:
h
= 视图高度 &w
= 视图宽度(例如 500x500)如果硬件加速关闭:
h
= 屏幕高度 &w
= 屏幕宽度(例如 1080x1920)
当 hardwareAcceleration
为 false
时,如何获取视图的尺寸?
How can I get the dimensions of my view when
hardwareAcceleration
isfalse
?
Canvas尺寸与View
尺寸无关。如果您想获得 onDraw()
内视图的大小,您可以使用 getMeasuredWidth()
/getMeasuredHeight()
.