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.
CardView使用了在"棒棒糖"版本上的属性值为阴影,并返回到老版本上的一个自定义的影子实现。
Due to expensive nature of rounded corner clipping, on platforms before Lollipop, CardView does not clip its children that intersect with rounded corners. Instead, it adds padding to avoid such intersection (See {@link #setPreventCornerOverlap(boolean)} to change this behavior).

由于在棒棒糖之前的平台上,圆角的代价很高,CardView不会对与圆角相交的子View进行剪辑。相反,它添加了填充来避免这样的交叉(参见setPreventCornerOverlap(boolean)来改变这种行为)。

Before Lollipop, 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.

在Lollipop之前,CardView在其内容中添加了填充,并在该区域内绘制了阴影。这一填充量等于:maxCardElevation+(1-cos45)的边距和码数,以及maxCardElevation 1.5+(1-cos45)的角半径

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 {@link #setContentPadding(int, int, int, int)} in code to set the padding between the edges of the CardView and children of CardView.

因为填充是用来抵消阴影的内容,所以您不能在CardView上设置填充。相反,可以在代码中使用XML或setContentPadding(int, int, int, int)中的内容填充属性,以在CardView的边缘设置填充。

Note that, if you specify exact dimensions for the CardView, because of the shadows, its content area will be different between platforms before Lollipop and after Lollipop. By using api version specific resource values, you can avoid these changes. Alternatively, If you want CardView to add inner padding on platforms Lollipop and after as well, you can call {@link #setUseCompatPadding(boolean)} and pass true.

注意,如果你为CardView指定精确的尺寸,由于阴影,它的内容区在Lollipop 和Lollipop版本之前是不同的。通过使用api版本特定的资源值,您可以避免这些更改。另外,如果你想让CardView在Lollipop上添加内填充,你也可以调用setUseCompatPadding(boolean),并设置为true。

To change CardView's elevation in a backward compatible way, use {@link #setCardElevation(float)}. CardView will use elevation API on Lollipop and before Lollipop, it will change the shadow size. To avoid moving the View while shadow size is changing, shadow size is clamped by {@link #getMaxCardElevation()}. If you want to change elevation dynamically, you should call {@link#setMaxCardElevation(float)} when CardView is initialized.

要用向后兼容的方式改变CardView的海拔,请使用setCardElevation(float)。CardView将在Lollipop上使用海拔API,在Lollipop之前,它将改变阴影的大小。为了避免在阴影大小变化时移动视图,使用setMaxCardElevation()来限制影子大小。如果您想要动态地更改海拔,您应该在初始化CardView时调用@link setMaxCardElevation(float)。

你可能感兴趣的:(CardView)