Question

I have used localization in my android application. Which supports two kind of layout in application.

I have used Fragment and Fragment Activity in my application.

If language is English then layout should be aligned to left as shown in image below.

Left Aligned Layout

And if language is Hebrew then layout should be aligned to right as shown in image below.

Right Aligned Layout

I am trying to load this layout by two different layout files and then I can detect which language and I can use appropriately.

Is there any other good methodology through I can use achieve this functionality without creating different XMLs for all layouts?

Can anybody please help me to resolve this issue?

No correct solution

OTHER TIPS

This should help: http://developer.android.com/about/versions/android-4.2.html#RTL

Android supports right-to-left layouts natively since android 4.2.

Creating two similar layouts those are having same @+id values is a clean approach but if you don't want to create two different layouts then you could simply set the layout_gravity attribute by code with some helper method and by getting the LayoutParams of the containers you are using in your xmls.

Edit :

From another answer , If it works for you with the support package i.e. v4 if you are targeting 2.2+ above then this would be an awesome approach to go with.

http://developer.android.com/about/versions/android-4.2.html#RTL

just came to know about this. Android is awesome!!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top