user3422687 user3422687 - 23 days ago 6
Android Question

android layout at different screen sizes

trying to get my head around screen sizes so my app looks the same on different devices.

I have two devices a galaxy s3 and a galaxy tab 8. both have the same resolution screen 720 x 1280 but the s3 is 4.7 inches while the tab is 8 inches

When I do a linear layout I set padding to 130 at the top so that the first textview is 130 pixels from the top so the image on the background is not obscured.

This is fine on the s3 but when I load it on the tab the padding needs changing to 190 pixels for it to look the same.

I cant get my head round if the height of the screen resolution is the same (1280) on both devices why do i need larger padding on the screen

is there a way of working out how to make the textview appear on the same location on both devices

Any help appreciated

Mark

Answer

Yes there is a way.

First off all you should use DP or SP unit instead of PX. The DP unit have in consideration the size of the screen and the screen resolution. You can see more in here:

Difference between px, dp, dip and sp in Android?

Also you can create a folder in res and add different sizes for different devices.

Example:

You already have the folder 'values' with the file 'dimens.xml' in there you can add margins and sizes variables.

If you create the folder 'values-large' and copie the file 'dimens.xml', you can change the sizes of the variables and maintain the name.

In devices 'large' it will load different values from the rest of the devices.

You can see all documentation in here: http://developer.android.com/guide/practices/screens_support.html

Hope it helps you.