androidviewstub

Use ViewStub in the ConstraintLayout, and the relative positioning change to "parent" while ViewStub is not inflated


I use the relative positioning between views as below examples. https://developer.android.com/reference/android/support/constraint/ConstraintLayout.html#RelativePositioning

In my case, the button A is a ViewStub, it inflated for specific cases. If the button A isn't inflated. Then relative positioning of the button B will change to "parent". Is it possible that the relative positioning of the button B change to "relative positioning of button A" while the button A isn't inflated ?


Solution

  • To restate you to views A and B. Normally if inflated A connects to (say) parent left B connects to A. |<-[A]<-[B]

    If A is a not inflated it is treated as gone. It and its margins are 0. So it looks as if B is connected to the parent with B's margin.

    You would like it to have the margin of A.

    The approach to doing this is to use the gone Margins in this example use "layout_goneMarginLeft". Setting its value to the same value as the left margin of A.