I have tried to create a custom NumberPicker which works in most of the cases pretty well. The only problem is the layout which is created dynamically. The layout consists of

* two buttons ("+" at the top and "-" at the bottom in portrait mode)
* one edit

In the constructor ("NumberPicker extends LinearLayout") I add the three components by using addView() to the layout.

In case of viewing this layout in landscape mode I would like the buttons "+" and "-" not to be at the top and the bottom, but on the right and on the left, because otherwise the size of the NumberPicker is too large.

By using the event onConfigurationChanged I check if the user has changed the screen orientation and set the orientation of the LinearLayout to horizontal and vertical. The problem is that the "+"- and "-"-Buttons are on wrong positions. It should look this way (e.g. in landscape):

"-" | edit | "+"

But it looks this way:

"+" | edit | "-"

How can I solve this problem? I would like to have the buttons in the right order. Could I solve the problem by using XMLs?

Thank you.