I am working on a android app which uses 29 different languages. I have created the layout according to english language in my resources folder but when the laguage changes the text views n text size changes and overlaps. Is there any way to keep the layouts constant for all laguages so that alignment of textviews and texts remain same?
yes very easy. you create for each language a values folder like values-de or values-en
in each folder you can create strings.xml
<string name="no_items">there are no items</string>
this is for the english one. create it for each language.
If you read the developer documents (here: http://developer.android.com/guide/topics/resources/localization.html#strategies), there is a good description of your problem and some ways to go about solving it. See the section "Design a flexible layout"
You can:
a) Provide different layouts per language with different layout files per language (although this can add a large amount of overhead for you to maintain your app)
or
b) Make a more flexible layout, so when long strings are passed in due to the language, everything adjusts by itself. Then you don't need to worry about which language the user is running in (or can create a lot less layouts specific to the language if some still don't look right).
you can extend TextView to adjust text size automatically to fit in.. an example of custom TextView is given in this answer https://stackoverflow.com/a/3378422/886001
Related
I'd like to have different layout design based on location. actually I know we can have different layout based on mobile device size.
As you know Android has very good feature that you can inflate all texts in your application based on location which is called Localization.
I am looking for a kind of similar feature that force my android app to inflate suitable layout design based on location.
In Persian and Arabic, the orientation of components is better to be Right-To-Left, although it is possible by designing exact wanted layout, but i don't know how to make it international because regardless of size, I need to have different layout design orientation based on user location, like USA, Germany, Iran and etc.
Is there any easy and automatic way to change layout orientation from left-to-right to right-to-left based on user location? I've checked similar question in stackoverflow, but that solution is not my aim and goal.
thank you :-)
You can use layout subfolders to provide different layouts depending on language direction. (layout-ldrtl).
Also You can provide different layouts depending on language (layout-ar in Your case).
In that case layouts that contained in simple layout folder will be defaults.
More info You can find in developer site
ofcurse, it has some ways to make it works.
RTL Layouts directory(the the right way)
The layout direction of your application. ldrtl means
"layout-direction-right-to-left". ldltr means
"layout-direction-left-to-right" and is the default implicit value.
This can apply to any resource such as layouts, drawables, or values.
For example, if you want to provide some specific layout for the
Arabic language and some generic layout for any other "right-to-left"
language (like Persian or Hebrew) then you would have:
res/
layout/
main.xml (Default layout)
layout-ar/
main.xml (Specific layout for Arabic)
layout-ldrtl/
main.xml (Any "right-to-left" language, except
for Arabic, because the "ar" language qualifier
has a higher precedence.) Note: To enable right-to-left layout features for your app, you must set supportsRtl
to "true" and set targetSdkVersion to 17 or higher.
https://developer.android.com/guide/topics/resources/providing-resources.html
Run time
https://stackoverflow.com/a/23203698
Set LAYOUT_DIRECTION="rtl"
and set GRAVITY="start"
My application needs to support languages that are read from right to left and vice verca.
Right now it supports only right to left, and all I need to do is change a bunch of layouts.
The approach I want to take is to have layouts in two different folders (i.e layout and layout-de), because doing it programatically, for every layout, is a nightmare.
However, Google state here http://developer.android.com/guide/topics/resources/localization.html#strategies
"you can create an alternative layout for that language (for example res/layout-de/main.xml). However, doing this can make your application harder to maintain"
My question is, which way is better, programmatically or separate layout folders
I want to stress, since this topic has been discussed in other threads:
I am NOT talking about strings. ONLY layouts
My only concern is the language orientation(left to right and right to left), when it comes to the layout.
Thank you very much in advance
Since Android 4.2 there is native RTL support. Most attributes that used "left" or "right" in their names now have equivalents that use "start" and "end" (e.g. android:paddingStart="..." or android:gravity="end").
Read about it here: http://android-developers.blogspot.com/2013/03/native-rtl-support-in-android-42.html
I'm designing an Android app that is to support 10 different languages/localities using Android Studio. The problem is that if I perfect the layout file for English it won't look right for other languages. For instance, some of the text might be truncated/cut off in another language because it is too long for the TextView, even if it is fine in English.
Is it possible to have language-based differences in font sizes in the layout (xml) file?
You should be able to create a layout-es folder to override the layout for the Spanish language etc. I have used it myself for drawables so I can't see why it wouldn't work for layouts too.
#darnmason's solution is correct -- locale-aware layout files do work, and to make it work, just duplicate the resource file in a layout folder with -xx, where xx is the language code. See the "639‑1" heading in this table for the language code.
So, for \res\layout\MainScreen.xml in French, the new file becomes \res\layout-fr\MainScreen.xml.
Despite Android Studio complaining that string resources should be localized into a (separate) resource file, it sometimes makes sense to use a duplicated locale-specific layout file; one such example is in the case referred to by the OP.
In general, try to do localization of text in a strings resource file. Sometimes, however, the translated text in one language would make the UI ugly in another language (compare length of "Nom d'utilisateur" with "用戶名", and the field sizes that result). In such cases, duplicate the layout file, as described above, as more than just the text (dimensions, perhaps fonts) is being localized.
The downside of using an additional layout file per language is that each time something changes (e.g. adding a button), multiple layout files need to be updated with all changes, rather than just adding the control to one layout file, and adding all translations to a separate strings resources file.
I would like to know if there is any good idea how to switch layouts according to application language selected - e.g. switch between left-to-right layout and right-to-left layout. Have different images or written text and ofcourse the position.
I thought doing it using a private member in the application that indicates the current language selected. According to this parameter I can choose the related XML and text etc.
Actualy I might create some LayoutFactory class, although I don't really think it is required.
But will have to create the realted layout XMLs.
Is there any option to put subdirectories under he layout?
Or should I name the files like en_.xml and he_.xml etc?
For values and drawable you can add folders like values-fr for French or values-ja for Japanese. The -fr indicates that if your phone is set to French localization the app will use any folder that has the -fr added to its name. I'm guessing this goes for the layout folder aswell.
You can read about Localization here .
What is the best way to provide the ability to switch between hebrew/english layouts in Android applications?
Is it commonly done - or usually just providing hebrew or english applications.
I know there is abikty to use localiztions - but is there Hebrew support for this?
Also my application should be for iPhone as well and I want to keep it the same.
How should do it in the code? Where to place the layouts?
Yoav
For orientation (right-to-left) you need: android.text.Layout.Direction
A hebrew TrueTypefont can then be called from a resource in your app by including TextView.
Instead of pushing 2 layout files you could use a class for hebrew and another for english...
or you could push the text to string values file for highest cleanliness
If it is a block of text that could be called from resource txt file (practical for prayers)
It all depends on how much text you have.