0

I'm confused about device independent drawing on Android.

Or rather, I have a canvas and I'm just drawing lines, rectangles and ovals on it.

Is there a way of doing this in a device independent viewport so that it just fits whatever screen its on?

I'm not trying to use bitmaps. Or do different layouts for different screen-sizes. I'm not too worried about the aspect ratio being distorted on very odd screens.

So I was hoping there was some kind of mode I could use where it took the arguments to drawOval etc. as device independent and just scaled them to fit the screen at whatever resolution and pixel density it had.

Is there something like this?

Or do I need to recalculate and scale all the coordinates myself?

interstar
  • 26,048
  • 36
  • 112
  • 180
  • Since canvas operations use pixels, you will have to do your own scaling. If you define your shapes in terms of device-independent pixels (dip), the conversion should be trivial. – Cheticamp Jun 17 '22 at 12:01
  • What does it mean to define my shapes in terms of dips rather than ordinary pixels? – interstar Jun 17 '22 at 12:05
  • 1
    See [Support different pixel densities](https://developer.android.com/training/multiscreen/screendensities). – Cheticamp Jun 17 '22 at 12:36
  • Sure. I understand in principle what a dip is. I guess my confusion is, if I am going to manually convert everything from an abstract space into the specific resolution for a screen, why do I need to worry about all these Android things like pixel density buckets etc? Why don't I just define my own abstract viewport, say 10000 x 8000 and scale everything from there to real pixels? – interstar Jun 17 '22 at 14:01
  • You can do that, too. You just need some device-independent space that can then be translated to each device as needed. – Cheticamp Jun 17 '22 at 14:17

0 Answers0