Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable automatic layout change on Android

Tags:

I've made an app, I've tested it and it was fine on my phone. But... when I gave the .apk to someone else whose phone language is RTL the whole layout broke and it messed up everything.

My question is - How can I force my app to use only LTR and disable the auto layout change which breaks my whole app design?

like image 980
Yehonatan Avatar asked Oct 19 '14 12:10

Yehonatan


People also ask

How do I disable RTL on Android?

Change all of your app's "left/right" layout properties to new "start/end" equivalents. If you are targeting your app to Android 4.2 (the app's targetSdkVersion or minSdkVersion is 17 or higher), then you should use “start” and “end” instead of “left” and “right”.

How to set animation for layout in Android?

Android offers pre-loaded animation that the system runs each time you make a change to the layout. All you need to do is set an attribute in the layout to tell the Android system to animate these layout changes, and system-default animations are carried out for you.


2 Answers

In your manifest file and inside the application tag add these two lines.

<manifest>     <application         .         .         .         android:supportsRtl="false"         tools:replace="android:supportsRtl" //(replace libraries' Rtl support with ours)         >     </application> </manifest> 

Note: (about second line) Some libraries have support Rtl in their manifest file so if you want to use those libraries you must replace their manifest line of code with yours.

like image 171
Eftekhari Avatar answered Sep 22 '22 13:09

Eftekhari


Android 4.2 added full native support for RTL layouts. To take advantage of RTL layout mirroring, simply make the following changes to your app:

  • Declare in your app manifest that your app supports RTL mirroring. Specifically, add android:supportsRtl="true" to the element in your manifest file.

  • Change all of your app's "left/right" layout properties to new "start/end" equivalents. If you are targeting your app to Android 4.2 (the app's targetSdkVersion or minSdkVersion is 17 or higher), then you should use “start” and “end” instead of “left” and “right”. For example, android:paddingLeft should become android:paddingStart. If you want your app to work with versions earlier than Android 4.2 (the app's targetSdkVersion or minSdkVersion is 16 or less), then you should add “start” and end” in addition to “left” and “right”. For example, you’d use both android:paddingLeft and android:paddingStart.

For more precise control over your app UI in both LTR and RTL mode, Android 4.2 includes the following new APIs to help manage View components:

  • android:layoutDirection — attribute for setting the direction of a component's layout.
  • android:textDirection — attribute for setting the direction of a component's text.
  • android:textAlignment — attribute for setting the alignment of a component's text.
  • getLayoutDirectionFromLocale() — method for getting the Locale-specified direction

-- Source & Credits --

like image 27
DroidBender Avatar answered Sep 18 '22 13:09

DroidBender