What is difference between Android margin start and right (or margin end and left)?
It is trivial question, but I cannot seem to learn from the documention what is difference between view start/end and left/right. It could be that I just don't understand something, but I cannot make any progress with this at all.
For left-to-right flow, start=left, end=right.
For right-to-left flow, start=right, end=left.
The "start" and "end" concepts were added in API Level 17, as part of Android 4.2's support for RTL layouts.
Android supports RTL layouts from API 17+ i.e., Android 4.2 (Jelly Bean).and when we make our layout to support both RTL and LTR then we can not use layout_marginleft and layout_marginRight there we use layout_marginstart and layout_maginend .
If you are familiar with languages like Arabic or Urdu you will be aware that they start from right to left unlike English where we read from Left to Right.
So if we set margins using Margin right/left then we don't care about the language but we just directly add the margin according to the universal left and right.
But if we use Margin start/end then we care about the language. So let's say if the app has a UI which is written in Arabic language then the start will be the right side and if the UI is in English the start will be on the left side.
Now when to use right/left and when to use start/end :
So if you are sure that your app is going to have no language needs and you need to show your UI from left to right always like in English language then you can opt for left/right margin as it's easy and simple to understand.
But if you are building a multi lingual app then you can opt for start/end margins as you don't have to create multiple UI's.
Related
I am programming an Android application. This application isn't translated to any right to left language (like Arabic or Hebrew). I've noticed that right to left language people has it in English, but with right to left layout. The drawer menu is on the right instead of the left and the text is right aligned.
What is the good practice to manage this? Should I let the RTL layout because they are used to it or should I force LTR layout because the app is in English?
If you’re not supporting RTL languages you should not support RTL layouts (LTR languages looks pretty bad in RTL languages).
Just add android:supportRtl="false" attribute in your manifest's application tag.
It should solve it.
Even though false is the default value, one of your dependencies can override it to true if you don't set it explicitly.
Confirm that this is the issue by checking the final merged manifest if android:supportRtl is true.
I am using an android library (leanback library for android tv) and want to set my app layouts independent of the system locale.
In other words, as all of my users use right to left language and layout, I want to prevent rendering layout in "Left to Right" mode even if system language is on a LTR lang like english.
So can I set a flag or do other stuff to make the app ignore system locale totally?
EDIT : Thanks to Andres comment, I followed this link and it works perfectly.
Use android:layoutDirection="rtl" for your layout's root and android:layout_gravity="start" for child views.
This way you force your layout to be right to left and all child views appear on the right side of the parent (start means right in rtl direction).
I have a multi language application. which works fine for the app is in the English language and all labels are placed perfectly at the required places.
Now I have a scenario when I change the language of the from English to Arabic app is doing the translation correctly. But issue is with the placement of the labels, I want to place the labels from rtl instead of ltr.
For API level 17 or higher Set the property textDirection in your XML
android:textDirection="anyRtl"
For below API level 17 use property textAlignment in your XML
android:textAlignment="viewStart"
In order to support RTL in your app, you first need to add android:supportsRtl="true" to the <application> element in your manifest file.
If your app API ≥ 17, replace all
layout_marginLeft with layout_marginStart
layout_marginRight with layout_marginEnd
paddingLeft with paddingStart
paddingRight with paddingEnd
and if your app support API<17 add layout_marginStart, layout_marginEnd along with layout_marginLeft, layout_marginRight
In addition to #Ankita's answer you can use textDirection:"anyRtl", which will set the direction of the text to the right if it finds any strong "right direction" character or to the left he it finds a strong "left direction" character
From Documentation of views
Text direction is using "any-RTL" algorithm. The paragraph direction is RTL if it contains any strong RTL character, otherwise it is LTR if it contains any strong LTR characters. If there are neither, the paragraph direction is the view's resolved layout direction.
I would recommend making 2 different layouts for each view one with left direction and one with right direction. In that case you will have the liberty to adapt your layout to the type of text you're going to have and so use textDirection="rtl"
Either cases are good, the first one from Ankita is useful when you don't need full control of the display and you can permit yourself to trust the "anyRTL" algorythm.
The second solution, gives you more work but will give you full control over the result layout.
One last thing. I'm not sure but by creating a layout with the arabic locale I think the text direction changes automatically
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 working on a relatively simple Android app. I want it to have an English version as well as a Hebrew version.
I have an activity all laid out in English, and I want to create the Hebrew resources. I couldn't find any easy way to do it. The only way I found was to take my layout/activity.xml file, put it in layout-iw/activity.xml and manually change everything so it appears right to left.
I need to reverse the order of all elements in any horizontally oriented container (all the columns in <TableRow>s, all the elements in horizontal <LinearLayout>s, etc...). I need to switch all layout_marginLefts with layout_marginRights, and of course - make all left-aligned controls right-aligned.
This is tedious, especially if I think about modifying the activity at some point - I'll need to modify the resources twice, and that alone gives me a headache.
There has to be an easier way.
Unfortunately you are correct this is exactly what you will have to do.
I would suggest using styles to format any elements where padding or margins need to change do to a switch from left to right text. If you construct your styles right it should limit the amount of line by line changes needed in individual layout files. However I do realize this is a case where hind-site is 20/20.