Is it possible to make margins collapse in Android? Let's say I have a LinearLayout
and add three TextView
s, each with an android:layout_margin
of 10dp
. I get the following result:
However, I'd like to get this result:
I know that I could workaround this by setting different top/bottom margins for the different items:
- set the top margin of the first item and the bottom margin of the last item to 10dp,
- set the remainding top/bottom margins to 5dp,
but that makes the design more complicated (especially if the TextViews are dynamically created). Is there some way to make the margins behave like in CSS? (For an explanation of why this makes sense, see: What is the point of CSS collapsing margins?)