I would like to add some space between the left display border and an ImageView. Android SDK made me aware of "android:layout_marginStart".
Consider adding android:layout_marginStart="10dp" to better support right-to-left layouts
Why should I use android:layout_marginStart="10dp" instead of android:layout_marginLeft="10dp"? I have never done so and never encountered any problems with so-called "right-to-left layouts".
start and end are the same as left and right for left-to-right (LTR) languages. For right-to-left (RTL) languages (Arabic, Hebrew, etc.), start and end reverse and become equivalent to right and left, respectively.
This Android Developers Blog post gets into a bit more detail.
Some APIs were introduced to support languages that use a right to left reading direction e.g Arabic and Hebrew.
One of which is android:layout_marginStart
See the link for more info : http://developer.android.com/about/versions/android-4.2.html#RTL
Related
I understand that texts may be LEFT or RIGHT on different languages, so that END or START may be useful for international apps.
However, LEFT or RIGHT as Gravity are also simple placement of things. If I want my button or icon to be aligned to the RIGHT, why on earth does lint complain on using END instead? Probably, if use END, the layout will become broken on a foreign device.
The documentation says:
android:layout_alignParentStart
If true, makes the start edge of this view match the start edge of the parent.
and
android:layout_alignParentTop
If true, makes the top edge of this view match the top edge of the parent.
So what's the difference between start edge and top edge?
I'm sorry if this question is already answered, I just couldn't find it. Blame my poor Googling skills.
As far as I know Layout attributes ending with "Start" are used to match the start of content direction like supporting RTL texts where the start of the View is not the default.
Native support of Right-to-Left (RTL) languages was introduced in Android v4.2 (Jelly Bean). Here is the official blog entry on this
To support RTL, it's advised to replace Left/Right layout properties to Start/End equivalents. Top/Bottom attributes, however, remained intact.
Please, read the blog entry for the details, there's no need to copy it here.
This question already has answers here:
What is the difference between Android margin start/end and right/left?
(3 answers)
Closed 5 years ago.
I was making a xml file and was applying gravity to make view content to shift it to extreme right side of window but i saw gravity as right and end.So, what is the actual difference between the both and which one to use where.
in Arabic, Persian and all rtl (Right-To-Left) Locales, end is left but for English and other ltr (Left-To-Right) Locales end means right
Left and right gravities might not work correctly in applications localized for right-to-left languages like Hebrew, Arabic etc. In those languages left and right sides are mirrored to european languages. If you use hardcoded left and right gravities for some elements of your UI, then they might be misplaced in right-to-left localizations. If you use begin and end, then Android will map them correctly to left or right depending on current system language. Thus begin for English is equal to left and for Hebrew to right etc.
If you app has a localization for one of right-to-left languages, then you should always use begin and end. Otherwise you can safely stay with left and right.
In my opinion when we set
android:orientation="horizontal" in the main layout, then it's better to set gravity of its child as start and end to make it more effective with the layout.
BUT
when other orientations are used then we can use other gravity forms as well.
I'm working on a relatively simple Android app. I want it to have an English version as well as a Hebrew version. (RTL Right to Left Alignment)
I have manually change the alignment to right in layout xml file. When a sentence contains digits (in the middle of it), the digits appear in a mirror view:
29 appears as 92, 21:45 appears as 54:12 and 2,000 appears as 000,2.
Also, when a sentence starts with digits or English characters, they get thrown to the end of the sentence messing it all up.
I think for android version 4.0.3 it supports Hebrew. I have check that in emulator.
So for older versions is there correct way to implement Hebrew?
Please help.
I think that Android's bidi analysis algorithm has some flaws. Unicode has two invisible, strongly directional characters that might help with these problems:
U+200E - left-to-right mark
U+200F - right-to-left mark
For the digit order problem, try putting left-to-right marks (U+200E) on both sides of the digit sequence.
Unicode also has the following bidi formatting codes:
U+202A - left-to-right embedding
U+202B - right-to-left embedding
U+202C - pop directional formatting (cancels the previous embedding or override)
U+202D - left-to-right override
U+202E - right-to-left override
For the problem with English fragments in Hebrew text, it might be as simple as putting a right-to-left mark before the English. (Android's algorithm may be under the impression that the paragraph is left-to-right since the first characters are English.) If that doesn't work, perhaps try surrounding selected text with some combination of formatting codes. (I'd try left-to-right embedding followed by pop directional formatting. I'd also try right-to-left embedding around everything combined with selective explicit right-to-left embeddings.)
The way these are supposed to affect text layout are defined by the Unicode Bidirectional Algorithm Unicode Standard Annex #9. However, if Android's implementation is broken (and I suspect it is), the best you can do is trial-and-error until you get things looking right. Good luck.
EDIT
As far as code is concerned, here's an example of how it might be done in Java:
String text = "גרסה \u200e2.100\u200e זמינה";
In XML, it might be:
<string name="update_available">גרסה 2.100 זמינה</string>
here is an example from my hebrew string xml, Thanks to Ted Hopp's answer:
you need to add '\u200e' before the char that causes you the problem:
<string name="basic_text1">המר על תוצאת המשחק\u200e:</string>
and the result will be:
:המר על תוצאת המשחק
I'm developing an application for Android in Persian. I fetch data from SQLite database and display them, using TextView. How can I display the text (that contains multiple lines ) from right to left?
Any Idea?
If the ROM supports right-to-left, which is most likely the case if you bought your mobile in the middle east, then you can set the gravity to right.
If Android does not support this natively (I'm not sure), you could create a string reverser that swaps the nth char with the string.length() - nth character until you have a reflected string, and then post that right justified.
If the ROM doesn't support right-to-left rendering, you could possibly use the java.text.Bidi class that implements the Unicode Bidi Algorithm.
This is an old question but since it wasn't asked very good it was not answered.
#Farina, I believe the answer you are looking for is here:
http://developer.android.com/guide/topics/resources/providing-resources.html
In essence: By creating a layout-ar folder right next to your layout folder and placing an rtl oriented layout file in it you can get it to show only on rtl selected devices. (ar stands for Arab, if using a different rtl language you may find the code here. Be-were that some devices support old-deprecated language codes so if it doesn't work try looking for older codes)