Difference between gravity right and end [duplicate] - android

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.

Related

What is the difference between paddingLeft and paddingStart in Android?

I was trying to set the padding of a LinearLayout in XML layouts of Android.
But it gives me 2 options - paddingLeft and paddingStart.
What are the differences, and is one the more correct/better attribute to use?
I want the best answer, because this needs the best quality code.
The short answer is: paddingStart is right-to-left (RTL)-aware, which paddingLeft is not.
You should favor paddingStart to make your app RTL-friendly, but make sure you test it (there's a developer option to force RTL on in your language, so you don't have to test your app in a language that you can't read).
If the user is in a locale that writes from right to left (RTL), then paddingStart will be applied on the right side, while if they're in a left-to-right (LTR) locale (such as English), it will be applied on the left side. paddingLeft, on the other hand, will always be applied on the left, regardless of the locale's text direction.
This is useful, because layouts are often reversed in RTL locales. For instance, a contacts list with contact photos might show the contact photo on the left for LTR locales, and on the right for RTL locales. Since the padding for the photo might be different than the padding for the other side of the item, you'd specify the paddings with paddingStart (for the photo's padding) and paddingEnd (for the padding on the other side of the item).
it's all about RTL support, if you choose paddingLeft then when your app operates in RTL Locale eg. Arabic your padding will be reversed. so, using paddingStart and paddingEnd is much more safer when trying to work with RTL world like Urdu or Arabic...etc.
Note : this doesn't matter if you assign the same values for Left and right padding, it obviously will behave the same in LTR and RTL worlds.

Why Android Lint strictly discourages the use of Gravity.LEFT or Gravity.RIGHT?

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.

Using custom fonts with mixed-language text on iOS and Android

We are working on an app that requires RTL and LTR language text on the same screen, often in the same sentence, rendered using custom fonts. This poses several non-trivial problems:
The design uses different custom fonts for each of the LTR and RTL
languages. If we use the LTR font, the RTL text doesnt look good and vice
versa.
RTL fonts have greater line heights than LTR fonts so if the line
height is adjusted for RTL, it gets messed up in LTR and vice versa.
One suggestion is to use text markup for language boundaries in multiline text. Then based on markup we will use the equivalent of <span>s in text labels and apply a custom font to each span with custom line height. This sounds like a solution that will require significant text processing on the device and may not be portable, so the questions are:
Has any one successfully tried this approach for mixed-language text rendering?
Are there any other suggestions to render mixed language text on mobile devices?
On android you can add different layout xmls for both ltr and rtl, just like you do for mdpi/hdpi/etc.. Thats the approach (as far as I know) you are expected to take. IOs I have no idea.

What is android:layout_marginStart

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

Android Hebrew (RTL) Integration

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:
:המר על תוצאת המשחק

Categories

Resources