Ok guys ... thanks for your input. It turns out the “Cartographic Documentation” mentions that:
Prior to L, CardView adds an addition to its content and draws shadows in this area. This number of add-ons is maxCardElevation + (1 - cos45) * cornerRadius on the sides and maxCardElevation * 1.5 + (1 - cos45) * cornerRadius on the top and bottom.
This means that the margin is intended for drawing shadows and modeling height. One possible solution for everyone having the same problem is to use the cardUseCompatPadding attribute in your layout as follows:
<android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" app:cardElevation="0dp" app:cardUseCompatPadding="true"> </android.support.v7.widget.CardView>
This will cause your layout to "display" the same way (the path to Lollipop // sad) on each device, regardless of the API. At least in this way we can fix the general layout, which works for all versions with this limitation in mind.
Hope this helps.
UPDATE: If you decide to go for "app: cardUseCompatPadding = true", here is another tip. Use a negative layout_margin to balance the unwanted add-on from the compatibility library. Example below:
<android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="-10dp" app:cardCornerRadius="0dp" app:cardUseCompatPadding="true" app:cardElevation="8dp"> </android.support.v7.widget.CardView>
Thus, your layout can get rid of unwanted filling. And look at the same pre-lollipop after the candy.
Hope this helps even more. :)
source share