Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using RecyclerView with Card

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?

like image 983
Yaroslav Rybalka Avatar asked Nov 12 '14 16:11

Yaroslav Rybalka


People also ask

How do you use card view in recycler view?

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).

What is Androidx Cardview?

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.

When should I use RecyclerView?

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.


1 Answers

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.

like image 170
yigit Avatar answered Oct 18 '22 12:10

yigit