change order of views in linear layout android

2020-01-27 07:46发布

问题:

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?

回答1:

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



回答2:

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.