Different sizes on 2 devices, even if I use "dp" - android

I've 2 tablets:
1 Samsung Android 3.0
DisplayMetrics {density=1.0, width=600, height=976,
scaledDensity=1.0, xdpi=161.55031, ydpi=155.51021}
1 Low cost device, Android 2.3.3
DisplayMetrics {density=1.0, width=480, height=800,
scaledDensity=1.0, xdpi=160, ydpi=160.42105}
If I use different layout for each screen size, both devices says they are large-long and mdpi, so I can't distinguish them by using layout folder names... The problem is:
I use a TextView with textSize="20dp"
In the firse device, text width is half of the screen, in the second device is bigger (80% of the screen width). Why? I expect that both devices display text in the same way if I use dp (and not px). I tried also with sp but nothing changes...
(I used TextView as example, I've the same problem with all elements in the layout: button sizes, ...)
I would try to use layout folder names like "layout-w600dp" or something else introduced in Android 3.2 but this is not the case.
I know I can change element dimensions by code in onLayout() but I don't want to do that...
Any suggestion?
Update
I solved my problems with layouts using themes: Activate a specific dimens.xml at runtime

The android documentation on Dimention say this
The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion
So it's totally ok what you see
You can achieve 50% of the screen using LinearLayout weigth..Refer this

Related

Android Design Screen for different screen size

app screen on galaxy s4 it skip right and bottom part because of small size mobile
I am having problem in Design different screen size.
how should all 5 categories will support most of the mobile screen?
my Android App Design Normal screen works on 5 inch mobile screen where as for 4 inch screen it skip below content.
for example it work nice on samsang galaxy s4 (5 inch) also on nexus 4.
but as shown in image when i see on nexus S(4 inch screen) it skip some bottom and right part .it cannot hold full layout mostly top and left part it display.
how to design normal screen which support these screen size changes?
is it compulsory to use wrap_content or Match_parent or fill_parent only to get rid of it.
for that also i am confused of specifying image size for different screen size in drawable.
also is normal screen be of different density such as hdpi,mdpi,ldpi etc.
how to solve this issue is it sufficient to use dp and sp?
and last one, in Android Studio we design 5 types of layout.for example activity_channel_list.xml(small). etc( for normal,large,xLarge).what last just activity_channel_list.xml represent.is it like if not any layout is selected.this will be selected by default.
Thanks in advance.
If you want to design layouts for different screens then make folders accordingly link
layout-mdpi
layout-hdpi
layout-xhdpi
layout-xxhdpi
If you don't want create different layout for different screens then simply use dimension file and create different dimens in that like
values-hdpi (dimen)
values-xhdpi (dimen)
values-xxhdpi (dimen)
and the difference between dp and sp is, we use dp for give dimensions to the image, and for size purpose and sp is use for define text size
the screen size id efferent and you cant make a layout for every one you need to try categorize the screen with layout selector
if you use sp for text the text size will change when user change the android font size and it is better to use dp for text
and last Question is like first one you need to categorize layout for size and density normaly
How should all 5 categories will support most of the mobile screen?
Take care if these following aspects while designing layouts:
1.Always design layouts inside scrollview, so that for smaller screens user will be able to view complete layout by scrolling
2.Use sp for text Sizes
3.Use dip(density independent pixels) for all widget sizes, usage of dip makes the size of widget according to mobile profile(like 240*320 may use ldpi so according widget size will change)
4.All the icons you are using you need to generate for all profiles(ldpi,hdpi,xxhdpi,xhdpi) and store in drawable-xxxx folder
If you dont want to generate images for all profiles you can use font icons (like font awesome,iconmoon)
font icons appear according to screen sizes.
5.Last but not least, avoid using hardcoded margins between widgets use attributes like gravity,center_in_parent etc.. so that screen looks uniform in all devices.

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
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.
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.
First of all, you need to use dp instead of px to do these kind of stuff. The reason the result is wrong is that the number of dots per inch on the s3 is much higher than that of the galaxy tab 8. You should really read this link to understand more.
[http://www.captechconsulting.com/blog/steven-byle/understanding-density-independence-android][1]

Android - dp units on layouts -look like bad idea?

Android developers site,and most of you,Push everybody to use dp units on their layouts,
I can understand this approach if you using different layout for different densities,but when my requires is one layout.xml ,and one drawable folder,it is make no sense to me to use it,
because it is NOT preserve proportion.
It seems weird to me that there is no simple way to preserve proportion for all devices.
Just help you to understand my point.
1.make any layout with view inside it
2.set the sizes on dp as Android advise you to do
3.and then check it on the eclipse graphical view of your XML.
It looks way way different between different size devices.
Button with width of 15 dp look like 10 times bigger in 640*480 devices then Tablets.
So what's the point?
I understand all the math of conversion between dp and pixel with density,
but i looking for simple way to preserver the proportion on my layout,without define others for others densities.
The only way that i find to help is using android:weightsum,
But it can not use for margins and other settings.
Any idea?
You can always use your values folder and implements the exact dp size for each of different device densities, so you wont create different layout on different density.
Tablet and handheld devices will never have the same sizes that is where the different layout folders are created to let the developers design on different devices.
I would recommend a different layout design on tablet and handheld devices which most apps applies.
Think of dp units as referring to actual size (like cm and inches). So something that is 250dp will look (for example) about 1 inch on a phone, but also roughly 1 inch on a tablet. No matter the size and resolution of the device, it will always be about 1 inch.
Why is it done this way? Well basically it is the Android creative vision that you won't simply scale your app from a handheld screen to a tablet sized screen. This is why they don't allow you to specify heights and widths as % of screen size. The one small exception is layout_weight in LinearLayout.
You may agree or disagree with their vision, but that's the reality.

Android Text Scaling on different resolutions same density

I have 2 devices, a 1024x600 7" tablet hdpi running Gingerbread and a hub attached to a touchscreen which is 1920x1008 22" in size, hdpi running ICS. The Android OS seems to consider both as "large" (240dp).
So, they have the same actual density (240dpi), same generalized density (hdpi), same generalized size (large) but different actual size (7" vs 22")
The text and spacing dimensions that I specify for my layout work great on the 22", but then on the 7" they look enormous and dont fit on the screen.
I've tried using dp and sp, no difference as I think the problem is that Android sees these things as the same size / density. Does anyone have any recommendations on how I can be able to scale sizes appropriately?
This program wil also eventually need to be supported on a 4.5" handheld as well.
Thanks in advance.
Sorry, my previous answer was completely wrong = )
Ideally, you should be able to design for the 7" tablet and have your layout scale up to the TV. But if that doesn't work you should be able to use something like layout-sw1008dp. The "sw" prefix allows you to specify the minimum dimension of the smallest side of the screen - so in the case of a TV, the height.
I am also facing such problem in my application. But i found a good solution for this.
I have only one layout for tablet and directory name is layout-sw600dp.
Now, when part came to height and width problems, I have created several different values directory in which i place dimensions and font size and other stubs. So there will be no constant value in layout of tablet screen.
androd:layout_width:"60dp" // i drop this scenario
androd:layout_width:"#dimen/tab_width" // i used this scenario
and your values directory name will be like
values-xlarge
values-large
All the values will be fetched from your values directory. It will not create different layout, but one layout can be used multiple times.
See my stack answer which may help you.

Layout Alignment Issues For Device to Device

When I try to run my project on LG Android Mobile then there is no alignment issues come with this device it is a 3.2 HVGA but when I try to run it on Motorola it is a 3.7 WVGA then it gives complete layout alignment issues so can you tell me suggestion to implement layouts uniquely to every device.
I don't know is it possible or not to make a unique layout design for all devices.
You can't create custom layouts for different devices, but you can for different screen densities and sizes, Supporting Multiple Screens has all of the information you should need.
You can create custom layouts by reading the device layout screen like this
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
There are two ways you can create your layout. You can create your own algorithm that checks the difference between the resolution you have made your layout for, and gets the difference for the current screen size, and adjust all those values progmatically (long and tedious, but DEFINETELY will work on all devices)
Or, you can define a layout for each of the common devices in your layout folder. This requires alot more space and time though.
Sometimes back I was having this type of problem. Because I was using Pixels as my unit to specify height, width or any layout specific dimensions. But I changed those px to dp and it worked for me. I got same layout for all the screens. Hope if this may help you anyways...
Here is a quick checklist about how you can ensure that your application displays properly on different screens:
1.Use wrap_content, fill_parent, or dp units when specifying dimensions in an XML layout file
2.Do not use hard coded pixel values in your application code
3.Do not use AbsoluteLayout (it's deprecated)
4.Supply alternative bitmap drawables for different screen densities

Categories

Resources