Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change order of views in linear layout android

Tags:

android

layout

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?

like image 919
Mohamad Ghafourian Avatar asked Jul 21 '13 19:07

Mohamad Ghafourian


3 Answers

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

like image 139
rekire Avatar answered Nov 20 '22 11:11

rekire


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.

like image 20
minipif Avatar answered Nov 20 '22 11:11

minipif


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

like image 1
Dima Karaush Avatar answered Nov 20 '22 13:11

Dima Karaush