23

As you know the order of views in linear layout is related to the order of them in xml file. Is it possible to change that order with java code by something like indexing?

Mohamad Ghafourian
  • 1,052
  • 1
  • 14
  • 26

3 Answers3

33

I would try to remove all views with removeView(view) and add them with addView(childView, index) in that order you like.

rekire
  • 47,260
  • 30
  • 167
  • 264
16

Remove the view, then add it to its new position by calling addView (View child, int index), specifying the position at which to add the view.

minipif
  • 4,756
  • 3
  • 30
  • 39
2

bringToFront() may be useful, as it changes the order for order-dependent layouts, too

Dima Karaush
  • 93
  • 2
  • 9