Reputation: 3675
I'd like to have different layout
design based on location
. actually I know we can have different layout based on mobile device size.
As you know Android has very good feature that you can inflate all texts in your application based on location which is called Localization.
I am looking for a kind of similar feature that force my android app to inflate suitable layout design based on location.
In Persian and Arabic, the orientation of components is better to be Right-To-Left
, although it is possible by designing exact wanted layout, but i don't know how to make it international because regardless of size, I need to have different layout design orientation based on user location, like USA, Germany, Iran and etc.
Is there any easy and automatic way to change layout orientation from left-to-right
to right-to-left
based on user location? I've checked similar question in stackoverflow, but that solution is not my aim and goal.
thank you :-)
Upvotes: 0
Views: 7020
Reputation: 3497
You can use layout
subfolders to provide different layouts depending on language direction. (layout-ldrtl
).
Also You can provide different layouts depending on language (layout-ar
in Your case).
In that case layouts that contained in simple layout
folder will be defaults.
More info You can find in developer site
Upvotes: 3
Reputation: 21
ofcurse, it has some ways to make it works.
RTL Layouts directory(the the right way)
The layout direction of your application. ldrtl means "layout-direction-right-to-left". ldltr means "layout-direction-left-to-right" and is the default implicit value.
This can apply to any resource such as layouts, drawables, or values.
For example, if you want to provide some specific layout for the Arabic language and some generic layout for any other "right-to-left" language (like Persian or Hebrew) then you would have:
res/ layout/
main.xml (Default layout) layout-ar/
main.xml (Specific layout for Arabic) layout-ldrtl/
main.xml (Any "right-to-left" language, except for Arabic, because the "ar" language qualifier has a higher precedence.) Note: To enable right-to-left layout features for your app, you must set supportsRtl to "true" and set targetSdkVersion to 17 or higher.
https://developer.android.com/guide/topics/resources/providing-resources.html
Run time https://stackoverflow.com/a/23203698
Upvotes: 1