android layout at different screen sizes

11,638

Solution 1

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:

What is the difference between "px", "dp", "dip" and "sp" on 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.

Solution 2

You need to add 2 different layouts for 2 different screen sizes. In fact you can provide multiple screen support limited only by your considerations. You can customize layout according to the screen sizes. Here is the official documentation to help you get going.

Share:
11,638
user3422687
Author by

user3422687

Updated on June 04, 2022

Comments

  • user3422687
    user3422687 almost 2 years

    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