Different dimension for different language - android

I'm working on a project, where in the textview the dimension of text is mentioned in a file main_dimens.xml in values-1024x768 folder. But i need a different text size for specific language(say pt).
<dimen name="main_digitalclock_size">18dp</dimen>
I need 12dp for pt language. So i tried to add the above line of code in strings.xml of values-pt folder, also created a folder values-pt-1024x768 and putted in it. But still size is 18dp only.

Are you sure you named your resource folders correctly? I looked up the rules that the Android OS uses when determining which resources to use here:
http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
It looks like the way to specify the usable screen size may be different from what you're using.

Related

what is dimens.xml(w820dp) in android studio.?

Upon creating the new project in android studio in the following path were created two xml files by default.
..res/values/dimens.xml
..res/values/dimens.xml(w820dp)
Am aware of the file dimens.xml where we can define the dimensions for the elements, but why the second file dimens.xml(w820dp) created by default.
Can someone please shed lights on why it is needed and when we can use it.
You can define several folders for each desired screensize in Andorid Studio. In your case, android studio defines values folders where you define dimensions (measurements) for scaling tablets or phones.
E.g. it defines two values folders like:
values-large
values-xlarge
or in your case
values-w820dp
Now inside this folders, a dimen.xml file is defined, where you can put your measurements in (unit dp) for the corresponding screensize.
Define a measurement like this:
<dimen name="value1">17dp</dimen>
Then embedd this sizes in your layout xml, like:
android:layout_height="#dimen/value1"
Depending on the screensize, the system will load the correct measurements from this folders, e.g. if you have a screen size large only the defined values in folder values-large will be loaded.
For more information, also have a look at https://developer.android.com/distribute/essentials/quality/tablets.html
EDIT1: So basically if you see the file dimen.xml(w820dp), the values in there are only used, if the app is executed on displays with 820dp and above, in this case, it means tablets.
In fact you have not file named ..res/values/dimens.xml(w820dp) at all in your project structure (check yourself). What you have instead is ..res/values-w820dp/dimens.xml file but to make editing right file easier, Android studio will (in Android view) show it as such. This file will be used by the framework on devices with display width 820dp or higher:
Specifies a minimum available screen width, in dp units at which the
resource should be used—defined by the value. This configuration
value will change when the orientation changes between landscape and
portrait to match the current actual width.
On other, "plain" dimens.xml will be loaded. See Providing Alternative Resources documentation on resource qualifiers to find out more about possible options and benefits.
Main use case of these files is to Support variety screen resolutions for user interface
dimens.xml
Android automatically take values from this file for device with dpi less than 820dp
dimens.xml(w820dp)
Android automatically take values from this file for device with dpi greater than 820dp
How to use
Declare dimension in these files with same name(dimens.xml)
<dimen name="button_width">200dp</dimen>
<dimen name="button_height">40dp</dimen>
Change only in their values (dimens.xml(w820dp))
<dimen name="button_width">400dp</dimen>
<dimen name="button_height">80dp</dimen>
w820dp
for screens with more than 820dp of available width. This would include 7"
and 10" devices in landscape (~960dp and ~1280dp respectively)
w820dp is a qualifier value to provide alternate values for different dimensions. This is used to localize to device types properly.

How to make UI in android for different devices

I'm fresher in Android & Coding. I have a task to design a popular game dots and boxes, for references https://en.wikipedia.org/wiki/Dots_and_Boxes . In this I have 7X7 cicles and used imageview to display all the stuff. My problem is how to design for multiple devices which looks as designed.
There is a great tool that lets you turn one image into multiple images for different screen densities: https://romannurik.github.io/AndroidAssetStudio/
There a few options there for generating the images, i use the Generic icons option since it allows an option for resizing the image.
if you use the generic option then:
Source: click image and upload the image (the circle for example).
Size and Padding: the defaults for size and padding are usually good enough.
Color: defaults to blue just move the seekbar to the far left in order to use the original color of the uploaded image.
Name and Download: at the bottom of the page you can rename the image see a preview and download as a zip.
Import: in the zipped file will be a res folder already structured properly by drawable densities and ready for you to just drag and drop into you /src/main folder.
P.S. Thank you to the person that made this tool your a genius and a life saver.
First of all use the unit dp for defining measurements. In addition to that, you have to define several values folders, where you define dimensions for scaling tablets or phones. E.g. define two values folders like:
values-large
values-xlarge
Now define a dimen.xml file inside this folders, where you can put your measurements in (unit dp) for the corresponding screensize. Define a measurement like this:
<dimen name="value1">17dp</dimen>
Then embedd this sizes in your layout xml, like:
android:layout_height="#dimen/value1"
Depending on the screensize, the system will load the correct measurements from this folders, e.g. if you have a screen size large only the defined values in folder values-large will be loaded. So instead of creating different layouts, define different measurements that can be loaded by the system automatically. For more information about this, also have a look at https://developer.android.com/distribute/essentials/quality/tablets.html

Use theme-defined settings OR from designer specification?

I have a design specification in PDF from my designer for all screens of my application. He made this specification according to Material Design Guidelines.
In this PDF all screen element sizes are specified. And I have all icon elements used in app in .png files. All of icons are exactly the same as in Material theme.
So the questions are: must I hardcode element sizes from specification or must I take them from correspinding sizes from theme? Must I put .png files from my designer to #drawable/ directory or must I use theme-defined icons?
Personally i save all my dimensions in a dimen.xml file and use them throughout my application. This allows for customization and if you ever want to adjust one margin, you can do it in one file and it will be set correctly in your entire application. It also gives you the ability to name your dimensions yourself, wich helps to make your code more readable. Here is a exampe of a dimen.xml file:
<resources>
<dimen name="action_button_min_width">56dip</dimen>
<dimen name="indeterminate_progress_size">32dp</dimen>
<dimen name="logoSize">#android:dimen/app_icon_size</dimen>
</resources>
EDIT: if you want to use a dimension given by android, but would prefer to give it another name, you can add it to your dimen.xml too, with another name. See the last dimen in the example.
If your designer has send you a document for you to follow, i'm sure he'd want some uniformity throughout the application. That's why google has released a big set of icons to choose from. This way, your app will have a consistent look & feel in all the windows from your app. Click here to check out the icon set.

Do I need style file in each DPI folder?

If I have only one style file in values folder and it contains items refer to items from dimens file then I don't get right result. Only if I will have style file in each values folder (MDPI, HDPI, etc) I will get right result.
That is a bit strange because for drawable I could have files only in one folder and resources for different DPI in other folders and it works fine.
Could someone explain how Android search style items when I use references from dimens?
Here is a little example.
values/styles.xml
<resources>
<style name="message_item_topic">
<item name="android:textSize">#dimen/message_id_topic</item>
</style>
</resources>
values/dimens.xml
<resources>
<dimen name="message_id_topic">12sp</dimen>
</resources>
values-hdpi/dimens.xml
<resources>
<dimen name="message_id_topic">15sp</dimen>
</resources>
As per the Providing Alternate Resources guide:
Android supports several configuration qualifiers and you can add multiple qualifiers to one directory name, by separating each qualifier with a dash. Table 2 lists the valid configuration qualifiers, in order of precedence—if you use multiple qualifiers for a resource directory, you must add them to the directory name in the order they are listed in the table.
The rules for finding the best matching resource:
Eliminate resource files that contradict the device configuration. (Exception: DPI)
Pick the (next) highest-precedence qualifier in the list
Do any of the resource directories include this qualifier?
If No, return to step 2 and look at the next qualifier. (In the example, the answer is "no" until the language qualifier is reached.)
If Yes, continue to step 4.
Eliminate resource directories that do not include this qualifier
As per the flowchart:
Each resource is loaded according to these rules separately (i.e., a lookup for each dimen happens for each, independent of the other resources). Any display issues you are having are probably due to not knowing the difference between things that scale by DPI (dp and sp) and things that do not (px) - use dp and sp and you do not need to declare alternate resources (for anything but drawables) for different DPI devices.
If you were using px, cm, in, ... then a different dimens.xml in separate values-(l|m|h|xh|xxh)dpi would make sense.
Things are relative.
And there are too many devices around.
You'll never be sure your app will fit on EVERY existing device.
Some users will contact you and ask a fix for their device.
So, you'll read the specs, make an emulator, add the specific drawable/values and rerelease your app. Keep in mind that TABLETS will require special drawable/values folders.

Where is the documentation on resource alias syntax and limitations?

I have an app that uses the same layout for all screen sizes (portrait only). The only difference is a handful of dimensions -- text sizes, margins, padding, etc. -- that vary slightly from one screen size bucket to another. Accordingly, I use a single layout xml file stored in the default layout folder, and have separate dimen.xml files stored in size-specific folders named with the minimum-size qualifiers (values-sw600dp, etc.)
But the Android documentation on Supporting Multiple Screens says that the minimum screen-width qualifiers don't work below Android 3.2. So I need to put dimen.xml files in values-small, values-large, values-xlarge, etc.
In order to avoid having to change the dimen.xml file for the same size (e.g., large and sw600dp), in two places, I'd like to alias one of the references. The very limited documentation I've found on using resource aliases doesn't make it clear whether I can alias a dimen.xml file, or what the correct syntax would be.
My preference is to store the actual dimen.xml file for a given size in the minimum-width folder (e.g., in values-sw600dp) and put an alias in the dimen.xml file in old-style size folder (e.g., in values-large). I think this would be the syntax:
<resources>
<item type="values" name="dimen">#values-sw600dp/dimen</item>
</resources>
Or would it be this:
<resources>
<item type="values-sw600dp" name="dimen">#values/dimen</item>
</resources>
I can't find any documentation on the syntax for an alias like this, or how the type field is interpreted. Is there any specific documentation like that?
And, is it even possible to do what I want? Can I alias a dimen resource? Is there a limitation such that I would have to store the master dimen.xml file in the default values folder (for example, "dimen_large.xml") and use aliases to refer to it in dimen.xml files in each of the two size folders?

Categories

Resources