1

I would like to know how to move a view already defined in a layout file to a different position (index) within it's parent (programmatically of course).

For example, take this:

<LinearLayout>
    <RelativeLayout id="1"></RelativeLayout>
    <RelativeLayout id="2"></RelativeLayout>
    <RelativeLayout id="3"></RelativeLayout>
    <RelativeLayout id="4"></RelativeLayout>
</LinearLayout>

And do this:

<LinearLayout>
    <RelativeLayout id="4"></RelativeLayout>
    <RelativeLayout id="1"></RelativeLayout>
    <RelativeLayout id="2"></RelativeLayout>
    <RelativeLayout id="3"></RelativeLayout>
</LinearLayout>

I would like to achieve this at runtime and have the results reflect immediately if possible. If not, I'm ok with have it occur only on onCreate().

PaulG
  • 6,920
  • 12
  • 54
  • 98

1 Answers1

1

Seems like you can use "removeView(view)" for your view and add it in runtime with "addView" in the order that you would like , check this post. I think that this is not the best solution if you look at performance but this is the best i could come with.

Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53
  • 1
    If another post already has the solution, then please flag the question as a duplicate, rather than posting an answer to point to another answer. – Mike M. Jan 17 '19 at 19:10