I have searched the documentation and have not found an answer so here we go:
Does Android have a resource qualifier to select between different resources when accessibility options are used? Like when the user sets font size to Huge.
I would like use different dimensions on some views when dealing with Huge/Small fonts.
Thanks in advance!
No, there is no resource qualifier for font scale. I assume you're aware of the sp unit for specifying text size. I would suggest either -
Make your layouts more flexible and sized based on their contents.
You can use getResources().getConfiguration().fontScale to determine the scale at runtime, and select or adjust your layout(s) accordingly.
This may cause more harm than good, and the docs explicitly say not to do this, but you could try using sp rather than dp for your various layout parameters as well.
Related
I am creating alternative layouts for my activities, for example sw320dp, etc. I plan to create another for sw480dp, and sw600dp, sw720dp.
In which segment falls the default layout, the one without qualifiers? So I don't duplicate code.
you can use a -nodpi qualifier to set the generics layouts.
It's totally acceptable to create sw320dp,sw480dp,sw600dp and sw720dp.
You don't need to think about the smallest width since it will choose on its own depends on the device size.
So just create those layouts 320-720 and if the device is not in those sizes it will just fall into the default one.
Hello I am using different textsizes depending on different screen sizes.
Like:
values-small: dimens.xml -> ?
values-normal: dimens.xml -> 10sp
values-large: dimens.xml -> ?
values-xlarge: dimens.xml -> ?
I want to know if there is a formula to set the right sizes depending on small, large, xlarge instead of setting sp size by testing it on different screens^^?
second question: is values-normal neccessary, isnt "values" folder == values-normal?
third question: what happens when I declare dimens.xml for small, normal, and large and the device is a XLARGE device will it use dimens.xml from values? or valuse-normal? or the next smaller one values-large?
thank you
I want to know if there is a formula to set the right sizes depending on small, large, xlarge instead of setting sp size by testing it on different screens
Not really. Many apps do not change their font size at all based on screen size, just as most Web apps do not change their font size based on browser window size. Of course, you are certainly welcome to specify different <dimen> resources for different screen sizes, including dimensions for use with text. And there's nothing stopping you from using an algorithm like the others suggest; just understand that there's no real reason to use that algorithm. To put it another way, a graphic designer should be telling you how big to make the text, not a calculator.
Moreover, the -small, -normal, etc. buckets are not used as much anymore, in favor of the more flexible -wNNNdp, -hNNNdp, and -swNNNdp buckets.
isnt "values" folder == values-normal?
No.
Suppose you have res/values-small/, res/values/, res/values-large/, and res/values-xlarge/. Further suppose that each resource set defines a text_size dimension resource, and you use that in in layouts (e.g., #dimen/text_size).
A -normal device will then pull from res/values-small/, as -small is for small screens or larger. Your res/values/ version of the resource will never be used. Hence, the typical pattern would be not have res/values-small/, putting your -small resources in res/values/, and overriding that default value in res/values-normal/, res/values-large/, and res/values-xlarge/.
what happens when I declare dimens.xml for small, normal, and large and the device is a XLARGE device will it use dimens.xml from values? or valuse-normal? or the next smaller one values-large?
It should pull from res/values-large/, as that is the closest match among the qualifying resource sets.
This is the common problem in majority of Android projects to support varied screen sizes.
In short, you can make use of scalable DP and scalable Font approach.
Android project structure inherently allows specifying different font size (SP) and margin values (DP) by defining them in dimens.xml files for supported screen sizes. But the problem that still remain is - what values to be used ? UX designers normally provide style guides for only one set (e.g. 360x640 DP screen size) and don't provide for all other supported screen sizes. So the problem to use right vlaues for other supported screen sizes still remain unanswered.
One good solution (per my understading) is to use readymade scalable dictionary of dimens.xml files, something similar to the dictionary of files provided by this library. After adding these xml files to project, you just need to use the keys in your layouts, then Android automatically uses font/margin value from respective directory. Please refer here for visual difference - with and without this approach.
I use the ratio 0.75 : 1 : 1.5 : 2 same as for DPIs. It works fine.
I am trying to define following layout folders
layout/my_activity.xml
layout-large/my_activity.xml
layout-xlarge/my_activity.xml
layout-xlarge-land/my_activity.xml
layout-land/my_activity.xml
layout-sw600dp/my_activity.xml
layout-sw720dp/my_activity.xml
Is this the complete list?Am i using all the possible layout folder combinations to support all screen sizes.
Sorry if it sounds silly but i am trying to confirm different layout folders i need to make for my App...
Take a look at this:
http://developer.android.com/guide/practices/screens_support.html
With the new qualifiers you can define size qualifiers based on arbitrary dp so you can't list "all the possible combinations".
I'm a little confused, hopefully somebody can clarify for me.
I have a dimens file in /res/values, but I want to override some of those default dimens for normal-mdpi screens. i.e. I want to have special dimens for normal-mdpi that won't affect the rest of my screen size / density buckets.
However, the dimens I put in res/values-normal-mdpi/dimens.xml are affecting other screen sizes / resolution buckets (e.g. large-xhdpi). I would expect large-xhdpi to still pull from res/values and not be affected by what I put in rev/values-normal-mdpi.
Does anyone why? And how I can achieve the desired effect?
This SO Question is very similar, and the answers to it very helpful (1) (2). Basically, the Android system will find the best match using these methods. For screen density, it will find the closest match and take that. It will only use res/values/dimens.xml if the dimension isn't in any of the density-specific directories.
In this case, create another version of dimens in any directory that will be a "better match" for the other devices that you want to support (ex: values-hdpi), and put the default values of the dimens that were overriden in there.
I am currently developing an Android Application for a company who are set on having this type of design and targeting Hires devices however I have found that this is very difficult to do and on some hires devices buttons start to stretch.
Screen design here: https://skitch.com/aaronwardle/r7kwa/screen
A few people have recommended making the buttons into Nine Patch PNG files which help with the various screen layouts.
Should I try and get a new app design for this project, which fits all screens using standard controls, or do you think this is achievable?
Looking at stats the most common devices are small screen ones, so creating this application may have a limited audience.
If any one has any pointers on what I could do, i.e. could I make this for hi res screens and within the application have a different layout for smaller screens?
Thanks Aaron!
Your question is too generic to give a simple and quick answer. Furthermore, the layout you want to make is complex and very non-native-looking which complicates matters. Please make sure you read and understand the official docs on the subject from HERE. There is no replacement for that...
The main points that come to mind from that document are:
the <supports-screens> manifest item
Resource directory qualifiers for screen size and density. Appending stuff such as -small or -portrait allows you to create resources that are loaded only on a particular screen aspect, size or DPI. For example, you can create bigger images for bigger screens, or change the layout XMLs for portrait or landscape
Use 9-patch images to scale up rectangles (buttons).
Best practices (as recommended by Google):
Use wrap_content, fill_parent, or the dp unit, instead of absolute pixels
Avoid AbsoluteLayout
Do not use hard-coded pixel values in your code
Use density and/or size-specific resources
I know my answer is a bit generic, but then again, so is your question...
You have to use 9 patch png and also will have to make some changes in the manifest file, to make it screen resolution free. These are very less changes in the manifest file so would not be a trouble.
You can use 9 patch images as well as to design application for different resolutions, you can create different layouts for landscape and portrait.