Quick question: at runtime I do a boolean check, if it returns true I would like to have two buttons in a relative layout on my MainActivity class. If its false I want to instead have two other widgets where those buttons would be (or near enough). How do I do that?
Share
If you have just those two alternatives put them both in your layout and hide / show the one you want. View#setVisibility()
If you want it more dynamic you can add and remove widgets programmatically. ViewGroup#addView()
Modifying a
RelativeLayoutduring runtime is quite complicated since you need to set all those layout parameters so you could add a simple layout like aFrameLayoutin the place where the buttons should go and put them inside the frame. Has the advantage that you can setup all the relative layout parameters for the frame in xml.