Reputation: 5542
When I set the hardware acceleration to false
in the AndroidManifest.xml
with hardwareAccelerated="false"
the method canvas.getWidth()
or canvas.getHeight()
falls back to a weird behaviour:
@Override
protected void onDraw(Canvas canvas) {
int h = canvas.getHeight();
int w = canvas.getWidth();
}
If hardware acceleration is on: h
= height of view & w
= width of view (e.g. 500x500)
If hardware acceleration is off: h
= height of screen & w
= width of screen (e.g. 1080x1920)
How can I get the dimensions of my view when hardwareAcceleration
is false
?
Upvotes: 2
Views: 118
Reputation: 62189
How can I get the dimensions of my view when
hardwareAcceleration
isfalse
?
Canvas size has nothing to do with View
's size. If you want to get size of the view inside onDraw()
you can use getMeasuredWidth()
/getMeasuredHeight()
.
Upvotes: 1