1

Many of my views have a second version, a left-handed version where I simply switch alignment for all buttons and imagebuttons from right to left or left to right.

I'm currently simply copying each layout and creating a left-handed version of it manually. When the app runs, it checks whether it should be left-handed or normal and will get the right layout to inflate.

Recently, my app started reporting many exceptions and I finally discovered that it's because I've added a new element to one of the layouts and forgot to add it in the corresponding left-handed version which caused crashes for people using the left-handed setting.

My question is:

What's a better way to have a second version of each layout where all left/right alignments are flipped, including relative layouts? Is there any way to share some of the layout?

SpaceMonkey
  • 4,143
  • 5
  • 38
  • 60
  • [This question](http://stackoverflow.com/questions/14904273/what-is-the-difference-between-android-margin-start-end-and-right-left "Start vs End Alignment") may be of some use to you, although it's only relevant to Android 4.2 and above. Although that depends on whether you're flipping for RTL languages, or just as part of your app. – PPartisan Aug 23 '15 at 11:18
  • @PPartisan thanks, I didn't know about that before. That would be nice except I have to support below 4.2 – SpaceMonkey Aug 23 '15 at 11:20
  • Are your left/right views changed at runtime? Or do they depend on the device your app's running on (i.e. could it be defined in `layout` folders.) – PPartisan Aug 23 '15 at 11:39
  • They are defined in layout folder. – SpaceMonkey Aug 23 '15 at 11:40
  • So you don't assign which layout file is used programmatically: it's all done through `xml`? – PPartisan Aug 23 '15 at 11:44
  • @PPartisan I do it programmatically – SpaceMonkey Aug 23 '15 at 11:45
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/87696/discussion-between-ppartisan-and-space-monkey). – PPartisan Aug 23 '15 at 11:46

0 Answers0