w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Android: Doing all my drawing on a SurfaceView; what's the proper way of making sure my drawing conforms to any screen size?

There's a very simple yet effective way to do it, you can declare all your sizes in a dimen file for each specific density/size, as you usually do for layouts e.g:

values/dimens.xml <--- With default sizes

values-sw600dp/dimens.xml <-- Tablets sizes


Now before you start drawing, load all the values in your program only once, maybe onCreate of your drawing activity, using the following command:

float someItemSize = Context.getResources().getDimension(R.dimen.some_itemSize)


That way, you let the operating system do the pixels conversion for you, you should do it only once and most important, this will give alot of flexibility to your code because you will be able to change sizes from xml files without even touching your actual code, hence, the customization should be easier as well as future changes...

Hope it helps!


© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.