How to target font sizes for different screen densities? - android

I am developing an android tablet application. To support different screen sizes I am using resource qualifiers
sw600dp - Nexus 7 like screens
sw768dp - Nexus 9 sized screens
sw800dp - Nexus 10 sized screens
sw840dp - Pixel C Sized screens
Now I came across a situation where the same 10 inch screen has different densities.
Nexus 10 #density 2.0
Kindle Fire 10 #density 1.5
Both these devices are fetching the values from the sw800dp folder. But in nexus 10 the font sizes are normal and on Kindle Fire 10 HD the font sizes are very large.
What's the best way to target these two types of screens?
Also am I following the correct method in targeting multiple screen sizes?

For Nexus 10 font size, create res folder. by default is portrait.
values-sw720dp-land
Happy coding!!

Make folders like this
values // default values
values-sw400dp
values-sw600dp
values-sw800dp
create dimen file in each folder for diffrent screen wise size

Related

Load different layout / dimensions depending on screen size and resolution in Android

I am trying to load a different xml file for the layout and dimens in Android. I have tried creating an xlarge folder (for 10 inch tablet) and large folder (for 7 inch tablet). So the folder are called values-xlarge and values-large or values-xlarge and values-large. The 10 inch tablet has a density of 224 ppi.
If I use these layout files, the layout file from the values-large folder is used for the 10 inch tablet. How can I load a different design for 7 and 10 inch tablets? And which appendix should be used to the folder? I have found small, medium, large, ..., sw700dp, sw600dp and mdpi, hdpi, etc.
I use sw720dp, sw350dp-land, sw350dp, etc.
The layout in the folder will be used for a screen with the smallest width (sw...) of 720dp, etc. ie. sw700dp will be used for screens with 700dp or more or up until the next sw???dp layout.
It is in Display Independent Pixels, not regular pixels. ie. pixel width divided by the screen dpi. You can also add a -land or -port to only use this layout if it is landscape or portrait.
Check out this link for more information.
https://developer.android.com/guide/topics/large-screens/support-different-screen-sizes

Android - Dynamic text scaling for same dpi but different screen size

In my app I create multiple TextViews dynamically and the text size for each one I derive from the value stored in dimens.xml under values folder. On one hand I have the Nexus 4 and on the other hand I have Nexus 10. Both have the same "xhdpi" density bucket but one has the screen size of 4.7 inches and other has a screen size of 10.05 inches. I can have the same value for textsize due to their same density bucket but the text appearing fine on Nexus 4 appears too small on Nexus 10. How can I have my text appear appropriately large on such devices ? Let me know if any files need to be included.
In your dimens.xml file use sp instead of dp.
Before
<dimen name="text_size">80dp</dimen>
After
<dimen name="text_size">80sp</dimen>
Create values-sw600dp and values-sw720dp and check in which one your tablet falls in. Set the dimension larger for the same key name in values-sw600dp and values-sw720dp based on your requirement.
After doing a lot more research I found out you can use both size and resolution specifiers together. I simply used values-xlarge-mdpi for Nexus 10 and values-large-mdpi for Nexus 4.

Properly defining dimens.xml to support both Android mobile and tablet devices

I have an app in the play store which runs on all mobiles and now I want to release it on tablets as well.
1) The images have been designed for xhdpi screens. So I think that will be sufficient to support tablets as well or should I redesign the images seperately for tablets?
2) I want to split dimens.xml into 3 categories -
dimens.xml for all mobile phones
dimens.xml for all 7 inch tablets
dimens.xml for all 10 inch tablets
The solution I came up with is divide the values folder like below -
values/dimens.xml
values-sw620dp/dimens.xml
values-sw720dp/dimens.xml
but since few mobile phones might fall into values-sw620dp/dimens.xml or values-sw720dp/dimens.xml, What is the appropriate way to divide dimens.xml into 3 categories??
Please do not post the below picture as I want to divide into 3 categories
Following is Struture Answered by Many
1) There is no tablet device in the market with higher density than xhdpi. Therefore, xhdpi images are sufficient to support tablets
2) Dividing the values folder as below will be helpful
- values\dimens.xml
- values-land\dimens.xml
- values-sw600dp\dimens.xml
- values-sw600dp-land\dimens.xml
- values-sw720dp\dimens.xml
- values-sw720dp-land\dimens.xml
The suffix -land is used for lanscape orientation.
Mobile phones do not fall into the sw600dp or sw720dp category. I think you are confused between dp and px.
Example:
Take Samsung Galaxy S7 Edge.
Resolution : 1440 x 2560px
Density : xxxhdpi
Converting 1440px to dp at xxxhdpi density, you get 320dp (Convert px to dp)
Therfore the width of Samsung Galaxy S7 edge in dp is 320dp and will fall in values\dimens.xml file
If you take a Tab and find dp similarly, you will notice that the dp will be greater than or equal to 600dp.

Android : Screen Size

I'm working on android application and got in trouble of multiple screen support. I developed the app for 1080x1920 and when i tested the app on my friends Micromax Unite 2 with resolution of 480x800, it was something else. So i made two folders in the layout as:
layout-1080x1920
layout-480x800
thinking that the 480x800 device will pick up the layout-480x800 folder. But no it used the layout-1080x1920. So what should i do? So that the device having resolution of 480x800 works on layout-480x800
I suggest naming the folders as such:
layout-sw600dp
Where sw600dp means Screen Width 600dp. This layout folder will be used by devices with screen widths of 600dp or more (typically all 7-10 inch tablets, or just very dense screen). And when you are targeting for the phone use just the layout folder without any specified criteria. All phones not matching the sw600dp will use the default layout resources. Possibly also consider using
layout-sw600dp-port
if you need to use specific layouts for portrait orientation, likewise you can do
layout-sw600dp-land
if you wanted to specified layouts for landscape.
The link cricket_007 provided is where I learned this information
Note that 1080x1920 equates to about 540 x 960 dp in dp measurement, which is why I suggested to use the particular 600dp for width
giving the folder names pixel according to android screen support dev page. Even if you know all possible resolutions for every device, the android system takes those *xml files/drawables etc specified by their DPI, not PX. Those dpi resolutions still can change on runtime, such as, when your activity uses a tool bar (which is not part of your dpi resolution). Name your folders layout-xlarge, layout-large, layout-normal, layout-small for *xml layouts. I suggest to put 4 different xml files with same name in each of them and try it again for different devices.

Android application for different screen sizes

As i new in android development i just want to know is there any way to develop Android application for different screen sizes ?
help me.
Thank you in advance
Just add this in your project.
res/values/main.xml
res/values-sw600dp/main.xml -> 7+ inches
res/values-sw720dp/main.xml -> 10+ inches
Create this folder and just copy your xml file in all the folders.
Put your main.xml in those folders:
res/values/ //your default values (in your case for phones)
res/values-large/ //specfic values for relatively big screens
res/values-xlarge/ //specific values for really big screens
large: Screens that are of similar size to a medium-density VGA
screen. The minimum layout size for a large screen is approximately
480x640 dp units. Examples are VGA and WVGA medium density screens.
xlarge: Screens that are considerably larger than the traditional
medium-density HVGA screen. The minimum layout size for an xlarge
screen is approximately 720x960 dp units. In most cases, devices with
extra large screens would be too large to carry in a pocket and would
most likely be tablet-style devices. Added in API level 9.
see more infos here: http://developer.android.com/guide/topics/resources/providing-resources.html#ResourceTypes
Google provide good article how to support multiple screens
http://developer.android.com/guide/practices/screens_support.html
General advices:
use layout - for for mobile phone layouts
use layout-sw600dp folder for 7inch tablets layouts
use layout-sw720dp folder for 10inch tablets layouts
use dimens.xml in values folder to define dimentions for your UI
you also can use
values-sw600dp and values-sw720dp with its own dimens.xml file for 7 and 10 inch tablets
Writing apps for multiple devices requires one to have good knowledge on basic concepts like : what is Dpi, Screen density , Orientation etc.
Article below is good place to start for:
Supporting Multiple Screens
http://developer.android.com/guide/practices/screens_support.html

Categories

Resources