I have some RecyclerView with Card items. And on preLollipop devices it looks fine. But on Lollipop it looks without any spacing between child cards. I tried to use margin and padding, but it didn't help. When I use margin on lollipop it looks fine, but with the same margin on preLollipop spacing is very big. Once again: why is there different spacings? Which property should I use to fix it?
Card Layout: A card Layout is used to display a list of data. It is the design of a single item of our RecyclerView. For creating a Card Layout navigate to the app > res > layout > Right-Click on it > New > Layout Resource File > Give a name to it(here card_layout).
androidx.cardview.widget.CardView. A FrameLayout with a rounded corner background and shadow. CardView uses elevation property on Lollipop for shadows and falls back to a custom emulated shadow implementation on older platforms.
RecyclerView is powerful when you need to customize your list or you want better animations. Those convenience methods in ListView caused a lot of trouble to people which is why RecyclerView provides a more flexible solution to them. The major change you need to make for migration is in your adapter.
This is happening because on L, shadows are outside the the View bounds but pre-L, they are inside the View (unfortunately there is no real shadow support pre-L).
If you want CardView to have same spacing on L as well, set cardUseCompatPadding to true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With