1

so, to the point, i'm right now working on a simple app, and for the app to working as intended i need to change my layout order on the component tree which hold different UI element

enter image description here need to move the relative2 layout to above relative1

i know that it tied to the XML file, but is it possible to do that without much hassle?

found this link before : Can I set "android:layout_below" at runtime, programmatically?

i already tried it, but it make my app crash when i execute it, i don't even know if that is what i need

would be grateful if anyone can help, thanks!

Community
  • 1
  • 1
Solid_Metal
  • 123
  • 1
  • 1
  • 17
  • Is inflating these layouts and then adding them dynamically an option? Then you can easily control the order. – Rafal Zawadzki Nov 17 '16 at 13:32
  • probably is, but honestly, i don't know where to start, since android studio environtment (or java in generral really) is still a new thing for me – Solid_Metal Nov 17 '16 at 15:07
  • You can't use layout_below because your view is in a LinearLayout. What you can do is get the views contained in the linear layout, remove all of them from the layout, and put them back in in whatever order you would like. – zgc7009 Nov 17 '16 at 15:09
  • 1
    thanks for the comment @zgc7009, didnt know that, meanwhile waiting for the other answer, i'll try to change the layout into full relative, and use previous code that i find, hopefully it;ll work – Solid_Metal Nov 17 '16 at 15:27

1 Answers1

0

So...

after looking up again on the internet, hundreds of stackoverflow thread i read (exaggeration of course) , i found one interesting thread here : How to bring view on front of everything?

it tho its probably what i need, tried it, and yes it somehow work, i dont know how/why, but it just work

heres the snippet of the code

RelativeLayout layouttype = (RelativeLayout) findViewById(R.id.relative1);
layouttype.bringToFront(); 

probably not the most ideal solution, but for now its good enough, thank you guys

Community
  • 1
  • 1
Solid_Metal
  • 123
  • 1
  • 1
  • 17
  • If one view overlaps another, bringToFront() will make sure the view in question has a higher z index and is shown on top of all others. If it's not an overlap thing I'm not sure why this works either :P – zgc7009 Nov 17 '16 at 16:24
  • the actual reason why i need to switch the layout position is to swap theirs position, both of the layout UI element actually not override each other, both are visible, and the layout relative size also not override each other. While using bringToFront work for some reason, i don't know if its actually swap the layout, thus it work but probably not like what i intended lol – Solid_Metal Nov 17 '16 at 16:31