Android Text Scaling on different resolutions same density - android

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.

Related

Android, different layout for 10.1 and 9.7 inch displays

I've developed an app for an specific 10.1 inch display (2560x1600) and my layout files are written to fit that specific resolution.
Now I need to make the same app to work with an 9.7 inch display (2048x1536).
It's the first time I have to do a thing like this and I don't know which is the right approach. Using the actual layout file in the new tablet is a bit of a mess, nothing fits correctly, is like making a zoom in the old one.
I've read a bit about creating folders for different layouts, but the problem is that if I create a folder "layout-sw720dp" both tablets use the same layout, which I don't want to.
Is the "different layout files" the right approach? If so, how can I specify a layout for an specific "resolution" or whatsoever?
Is there other way to approach this?
Thanks!
In Android, there are different types of attribute qualifiers which helps us to design the app for different types/resolutions of devices. However in this particular case here, both the resolutions would come under the same attributes for almost all the qualifier types.
They both would come under the xhdpi bracket for xlarge devices. So you cannot use these qualifiers. But the one thing that is not same will be the shortest width qualifier for the two resolutions.
The shortest width for 2560 x 1600 would be 800dp and shortest width for 2048 x 1536 would be 768dp. So you can use the layout-sw<>dp attribute to distinguish the two devices.
for 10.1 inch display (2560 x 1600) : layout-sw800dp
for 9.7 inch display (2048 x 1536) : layout-sw768dp
When you use the layout-sw720dp folder, both the devices will take the same folder as the shortest width of both devices are greater than 720. Check this developer doc section (especially the table) for more information.
In the app folder of your application in android studio , go to the res-> layout, right click on that select New -> Layout resource file. on the new resource file window ,give file name dimens.
on the available qualifiers select dimension and push it into the chosen qualifier and specify the dimension as 2048x1536. you can use this file to specify the layout for tablet of dimension 2048x1536.
If you layouts are properly designed layout-sw720dp should handle both tablets flawlessly.
how can I specify a layout for an specific "resolution" or whatsoever?
For this part there are 2 types of width prefixes. layout-wXXX is for devices whose width is exactly XXX, nothing more, nothing less. Whereas, layout-swXXX is for devices whose width is at least XXX.
Again, well designed layout-sw720dp folder should cover both your needs.

calculate dp for different screen for supporting multiple screens

I know there are many questions like this, I have read many blogs and questions on this and I am not satisfied by what I have understand.
I want to support multiple screens and resolutions like hdpi, xxxhdpi etc.
And i am using dimens.xml for this purpose. But m still unclear about how to calculate exact dp value for different screens.
For example if 48dp x 48dp ImageView is proper for hdpi device, what values should i define for xxhdpi device? Is there any fixed calulation just like there is for drawable images?
I am using these folder for trying to support multiple screens :
values-sw320dp-hdpi
values-sw320dp-xhdpi/xxhdpi/xxxhdpi
There are few problems I am facing currently
Though defining values in respective dimens.xml works almost for most of the devices, there are few devices which takes wrong values
For example I have Lg optimus G that is xhdpi device, but it reads values from values-sw320dp-xxxhdpi's dimens.xml instead of xhdpi one
I am not able to calculate the exact value for each resolution (hdpi,xhdpi etc), so the view which looks perfect in hdpi device, seems little large or small in xxxhdpi as I can't guess the value like if hdpi view size is 48dp then xxxhdpi should be of 64dp or something as I don't know the exact approach.
Also while searching for supporting different screens, I read many times about calculating dp at runtime based on density or calulating pixels etc.
I am too confused about all this. Please help me in understanding and learning the proper way of making responsive apps.
You can use resource qualifiers to specify different sizes for Views.
If you want the width of an ImageView to vary based on the size of the screen, create a new dimension in your dimens.xml file called image_view_width (for example).
This then essentially creates a copy of the dimens.xml but adding the 'Size' qualifier. This will create another version of the dimens.xmlfile, and any device that meets your specified qualifications will use that version of dimens.xml. You then add image_view_width to this new file and give it a different (smaller/bigger) value. You can do this as many times as you want and with as many different qualifiers as you want.
Finally, when you want to use this value in your layouts, you only have to type:
android:layout_width="#dimen/image_view_width"
and android will do the rest for you.
Hope this helps!

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]

Density-specific layouts vs. size-specific layouts in Android

For quite a long time, I have been declaring resource folders for 4 different densities:
drawable-ldpi
drawable-mdpi
drawable-hdpi
drawable-xhdpi
In the layout's XML, I have been using fixed widths (while still density-independent) such as 128dp for those graphics.
However, when more and more large-screen phones, and especially tablets, were introduced, that approach did not work anymore. Although you provide density-independent resources this way, the layout will not look good on large screens.
This is why I think I need to add Dimension resources that depend on the screen size, for use in the XML layouts, e.g.:
values
values-w600dp
values-w720dp
values-w1024dp
But does that mean that I should drop supporting those 4 density containers? Or do I need to provide 16 resource folders, i.e. one for every combination of density and size?
I can't find any good help in the Android documentation as to this topic.
drawables and layouts are different. To answer your question, should you stop support those densities. Yes, but you should still support xdpi and hdpi. Romain Guy recently said that modern devices like the Nexus 7 (at a tvpi) can scale the assets properly enough that mdpi isn't really needed. And nobody uses ldpi anymore. Last I looked is was less than 2% of the market.
About layouts. A Nexus 7 (1280x800 tvdpi) would use something from the values-w1024dp but still get assets from the drawable-hdpi folder. Those two aren't mutually exclusive. Something like a S3 would also pull from the values-w1024dp but use drawable-xdpi. You only need to provide an alternative layout if your use-case calls for it.
So do you need 16 different things? No. You do need xdpi & hdpi (if not mdpi). You may want to include alternative layouts for different sizes. You can be as specific as you want or as generic. Unless you're doing a hybrid app for both phone & tablet (7 & 10 in) you probably don't need a lot of xxxx-sizexxx folders.
In the layout's XML, I have been using fixed widths (while still density-independent) such as 128dp for those graphics.
This is probably a source of your issues. Your layouts should be as fluid as possible using wrap_content and match_parent. Fixed sizes should be reserved for padding around the sides and image where you know the size ahead of time. If you do this, your layout should look decent at any size from a small 320 x 200 to a GTV size.
1) Regarding dimensions in your layouts (values/dimens.xml):
values values-w600dp values-w720dp values-w1024dp
But does that mean that I should drop supporting those 4 density
containers? Or do I need to provide 16 resource folders, i.e. one for
every combination of density and size?
No, you don't need to provide different dimensions per dpi bucket (hdpi/xhdpi), because the dimensions are already being scaled up or down based on the device (if you're using dp instead of px). So for dimensions, you only need to provide values for devices with different sizes (hence the name, values-smallest possible width-600-dp). Because you don't want 16dp padding on a phone AND 16dp on a 10" tablet as well. You'd want 64dp instead. And no, it doesn't matter what density the device has. It still needs to have the same padding on the respective device width. So for dimens, you only need to think about the device's actual physical dimensions.
2) Regarding drawables scaling for different resolutions (drawables/xdpi):
The system scales them appropriately for the device. You don't need to worry about this. Also, you don't need to add any other buckets here. Just use mdpi/hdpi/xhdpi and maybe xxhdpi because many new devices are going to use the new density in the future.
Conclusion: there are 2 different UI building components that vary according to 2 different rules: drawables based on screen density and dimensions based on screen size. Do not mistake one for the other and think you need tens of buckets in the values folder, because that's not only wrong, it's just mind boggling.

Resolutions and densities

I am developing for android and my code runs perfect on nexus or any 3.7 inch device.
If I run it on tablet (7 or 10.1 inch) then the fonts and buttons are very small and the spacing is way too big.
If I run it on 2.7 QVGA then the buttons are too big and overlap.
I am using dp and sp all over the layout so I am surprised it didn't adjust according to different screen size/density.
Does that mean that I have to wrte the same XML layout in 3 layout folders (large, medium and small) and put my drawable in 3 different density folders?
Or am I amissing something here. Yes I read the "Supporting multiple screen" document and it just loses me with the details (but I did follow the tips of using dp and sp). I am looking for more of a summary/general approach answer.
dp and sp adjusts according to screen density. Therefore, a screen with 500 dpi and 4000 dpi but with the same SCREEN DIMENTIONS will looks the same.
If they have different screen sizes, it won't fit as you want. If you want to support multiple screen sizes, you'd have to use weights or percentages.
The key is that dp = device independent pixel and it only adjusts according to density, not screen size.
In the most cases if you don't make a tablet app, you don't need to make more than one XML layout for different densities/sizes. All you must do is define dimensions with DP and SP as you said.
But is necessary to provide different images in the drawable folder to show one or other in function on screen size/density.
If you put all images in drawable folder (without specify hdi,ldi or mdi) Android will try to adjust the images but not always works fine.
Hope it helps.

Categories

Resources