Android CardView padding and minHeight

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-15 14:25:48

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/26439988/android-cardview-padding-and-minheight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!