Sebastian Schneider
Sebastian Schneider

Reputation: 5542

Get canvas size in custom view with hardwareAcceleration set to false

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();
}

How can I get the dimensions of my view when hardwareAcceleration is false?

Upvotes: 2

Views: 118

Answers (1)

azizbekian
azizbekian

Reputation: 62189

How can I get the dimensions of my view when hardwareAcceleration is false?

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

Related Questions