I have traveled all over the internet looking for a way to do something that I thought would be very basic. Bottom line is: I have an android UI that I have designed. It consists of buttons that are placed along the middle of the screen. This is sort of a menu screen. These buttons need to be in the SAME location but should just increase or decrease in size in relation to the physical size of the screen. Basically, if i have a button on a screen that is 1px (or dip; dip is what i currently use in my application) X 1px, then, if i double the screen size, the button should auto-format to 2px X 2px. I have done the math on my application. The button that I have is about 225/854 down the screen (this comes out to be about 26.44% from the top.) All I want to do is make that button come down the same amount. Say I reduced the size of the screen to 500, the ratio should stay the same.
Example math work:
(225 dip/854 px)*100=26.44%
so if I reduce the screen size to 500px, the dip should be as follows.
(225dip/854px)*500px = 131.733021077283372 dip
Is this the best way to go about scaling my buttons? If so, how do I tell my application to calculate the correct number of dip that the button should be placed at?
If you are still confused (sorry!), here is a key to looking at that work.
225dip = how far the button comes down from the top of the screen.
854px = physical size (in pixels) of the screen
131.733021077283372 dip = new number of dip if screen is reduced to 500px physical size
If you design your interface using dip (or dp) and sp units (for fonts) you can let Android do the scaling for you. Although maybe not pixel perfect on every device, your app will certainly look the same on many devices in the correct scale.
Supporting multiple screens on http://d.android.com describes this…