stoefln
stoefln

Reputation: 14566

android: onMeasure is called too often

I'm currently developing a camera app, where I have to set the camera preview size dependent on the size of the (fullscreen) app view. THe prozess involves waiting for the onMeasure event to get the size of the view, calculating the right size considering several other parameters (padding, camera picture sizes, ...).

The problem is: onMeasure is called at least 5 times, and several times giving me strange resolutions like 800x800 on a device with 800x400 screen resolution. This is not ideal, since I have to recalculate the optimal size again each time, and that brings a lot more complexity into my app, and makes it even slow.

Do you have any idea how this could be improved? Reading display.width() and height() would be so much simpler, but i guess that's no option, even for fullscreen apps, right?

Upvotes: 3

Views: 1934

Answers (1)

Lumis
Lumis

Reputation: 21639

Have you tried onSizeChange() ?

This can also be called more than once, but I have never got wrong dimensions... and you can put a flag not to run additive operations more than once.

Upvotes: 3

Related Questions