Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 829
user3422687 Avatar asked Oct 20 '22 02:10

user3422687


2 Answers

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.

like image 72
Bernas Avatar answered Nov 09 '22 04:11

Bernas


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.

like image 38
Naddy Avatar answered Nov 09 '22 04:11

Naddy