Disable automatic layout change on Android

后端 未结 3 732
耶瑟儿~
耶瑟儿~ 2021-02-02 12:07

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 e

3条回答
  •  -上瘾入骨i
    2021-02-02 12:23

    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 --

提交回复
热议问题