Search code examples
androidandroid-support-libraryandroid-cardview

Android CardView padding and minHeight


Today I updated support dependencies in my project and I found some issues with the new CardView.

Previous version:

compile 'com.android.support:cardview-v7:21.0.0-rc1@aar'

Current version:

compile 'com.android.support:cardview-v7:21.0.0@aar'

First of all it looks like minHeight doesn't work any more. One of the solutions is to put any ViewGroup inside the card and set the minimum height, but it looks like a bug for me.

The second issue for me are paddings. With the new library release paddings are larger. If you put some cards next to each other the gap between them is way to large. I've tried setting the padding to 0dp but it looks like the padding comes from 9.png file. The code pasted below doesn't change anything.

<android.support.v7.widget.CardView
    android:padding="0dp"
    ...

I've also tried with negative values but also nothing. Is there any way to solve this two issues for pre-Lollipop devices?


Solution

  • About the padding stuff you have new information here: http://developer.android.com/reference/android/support/v7/widget/CardView.html

    Before L, CardView adds padding to its content and draws shadows to that area. This padding amount is equal to maxCardElevation + (1 - cos45) * cornerRadius on the sides and maxCardElevation * 1.5 + (1 - cos45) * cornerRadius on top and bottom.

    Since padding is used to offset content for shadows, you cannot set padding on CardView. Instead, you can use content padding attributes in XML or setContentPadding(int, int, int, int) in code to set the padding between the edges of the Card and children of CardView.