I have 2 buttons that are aligned vertically in Android XML layout. There is a 16dp space between the two.
I would like that space to toggle based on both buttons' visibilities.
Like this when both are visible (16dp margin between them):
Like this when button 1 is gone (no margins and button 2 shifts up):
Like this when button 2 is gone (no margin below button 1 now):
I tried LinearLayout, ConstraintLayout with vertical chain but didn't find any solution.
Any help would be great.
If you are using ConstraintLayout
you can achieve what you want with the layout_goneMarginXXX
attributes.
You can read more about it in the ConstraintLayout doc
For your problem all you have to do is set:
...
layout_goneMarginBottom="0dp"
...