Comparison of layout details of Android development: RTL mode

Source: Internet
Author: User
Tags comparison locale

Objective

To tell the truth, long time no blog, 2016 are half past, hurriedly picked up again. (Personal feeling, and content is irrelevant ...)
The so-called RTL, as the name implies that is right to left, is an Arabic, Persian, and other cases from right-to-left reading way. This adaptation is required when developing an app that is intended for overseas users.

Starting with the Android 4.2 support for native RTL mode, I don't want to make any more explanations for the previous versions, and if the old versions still support that Android fragmentation will never end.

Body

How to view effects

The first thing to say is that you want to see RTL mode, do not have to put the language/country in the mobile phone to the Arab and so on, only in the "Developer Options" to check "force the use of right-to-left layout direction", which is really convenient too much.

Here take MIUI as an example, we might as well try their own hands.

As shown in the diagram, the control of the left and right sides has been reversed, it is noteworthy that the red Box callout icon in the figure has been flipped (more standard version is "Mirror").

How to support RTL

Isn't it fun, if you fit RTL in your app?

1, need to make a declaration in the support of the checklist file Corps RTL, put it under < Application > node.

Android:supportsrtl= "true"
2, replace the "left and Right" attribute in the layout with the corresponding "Start, End" property.

This step may be said not clear enough to see the code to look at the picture!

<button
Android:id= "@+id/button"
android:text= "A"
Android:layout_width= "60DP"
android:layout_height= "40DP"/>

<button
Android:id= "@+id/button2"
android:text= "B"
android:layout_torightof= "@id/button"
Android:layout_width= "60DP"
android:layout_height= "40DP"/>

<button
Android:id= "@+id/button3"
android:text= "C"
android:layout_torightof= "@id/button2"
Android:layout_width= "60DP"
android:layout_height= "40DP"/>

You should be able to see that this is in a relative layout, by default:

When RTL is turned on, it is like this:

Why is the B, C button missing? Because they are all on the right side of a, depending on the property, this has exceeded the screen boundary.

If we make a little change to the layout:

Android:layout_torightof
Change into
Android:layout_toendof

If you have left, you can also copy it to start.

page does not want to support RTL what to do

There are some interfaces you don't want it to support RTL, or it doesn't need to support itself, so what? For example, dial the interface, do you want to mirror the number key also past it:

Just need to add such a sentence is good.

Layoutdirect can use 4 of properties:
LTR: From left to right
RTL: From right to left
Inherit: Inheriting from the upper view
Locale: decided by locale

The corresponding int value is 0,1,2,3.
What about the pictures?
Just create a folder, put the image behind the mirror, you can not make any changes in the code.

drawable-ldrtl-xhdpi
drawable-xhdpi

The resolution is one by one corresponding.


Of course, in addition to the image preprocessing, if you want to use direct control of the code is also possible.

Private ImageView Image2;

Omitted

Image2 = (ImageView) Findviewbyid (r.id.image2);

Drawable arrow = Getresources (). getdrawable (R.drawable.arrow);
if (Build.VERSION.SDK_INT >= build.version_codes. KitKat) {
if (arrow!= null) {
Arrow.setautomirrored (TRUE);
}
}
Image2.setimagedrawable (arrow);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.