Android CardView 填充和 minHeight

标签 android android-support-library android-cardview

今天我更新了项目中的支持​​依赖项,发现新的 CardView 存在一些问题。

以前的版本:

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

当前版本:

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

首先看起来 minHeight 不再起作用了。解决方案之一是将任何 ViewGroup 放入卡片中并设置最小高度,但对我来说这看起来像是一个错误。

对我来说,第二个问题是填充。随着新库的发布,填充更大。如果你把一些卡片放在一起,它们之间的差距就会很大。我试过将填充设置为 0dp 但看起来填充来自 9.png 文件。下面粘贴的代码不会改变任何内容。

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

我也尝试过负值,但也没有。对于 Lollipop 之前的设备,有什么办法可以解决这两个问题吗?

最佳答案

关于填充内容,您在这里有新信息: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.

关于Android CardView 填充和 minHeight,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26439988/

相关文章:

android - 将支持库布局属性提取到样式中

android - 如何使用单独的线程来执行http请求

c# - 如何使 Xamarin 应用全屏(全屏)

android - 如何使用 v7/v14 首选项支持库?

android - 删除 TabLayout 中的换行符

android - 网格中的 CardView 不在所有侧面显示阴影

java - 如何发送 Whatsapp 消息到新号码

java - Android 版 Google MapActivity 中的资源使用情况

java - 如何以编程方式设计线性布局

android - 具有不同角半径的 CardView