A FrameLayout with a rounded corner background and shadow.
一個(gè)帶有圓角背景和陰影的框架。
CardView uses <code>elevation</code> property on Lollipop for shadows and falls back to a custom emulated shadow implementation on older platforms.
CardView使用了在"棒棒糖"版本上的屬性值為陰影,并返回到老版本上的一個(gè)自定義的影子實(shí)現(xiàn)。
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).
由于在棒棒糖之前的平臺(tái)上,圓角的代價(jià)很高,CardView不會(huì)對與圓角相交的子View進(jìn)行剪輯。相反,它添加了填充來避免這樣的交叉(參見setPreventCornerOverlap(boolean)來改變這種行為)。
Before Lollipop, CardView adds padding to its content and draws shadows to that area. This padding amount is equal to <code>maxCardElevation + (1 - cos45) * cornerRadius</code> on the sides and <code>maxCardElevation * 1.5 + (1 - cos45) * cornerRadius</code> on top and bottom.
在Lollipop之前,CardView在其內(nèi)容中添加了填充,并在該區(qū)域內(nèi)繪制了陰影。這一填充量等于:maxCardElevation+(1-cos45)的邊距和碼數(shù),以及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.
因?yàn)樘畛涫怯脕淼窒幱暗膬?nèi)容,所以您不能在CardView上設(shè)置填充。相反,可以在代碼中使用XML或setContentPadding(int, int, int, int)中的內(nèi)容填充屬性,以在CardView的邊緣設(shè)置填充。
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 <code>true</code>.
注意,如果你為CardView指定精確的尺寸,由于陰影,它的內(nèi)容區(qū)在Lollipop 和Lollipop版本之前是不同的。通過使用api版本特定的資源值,您可以避免這些更改。另外,如果你想讓CardView在Lollipop上添加內(nèi)填充,你也可以調(diào)用setUseCompatPadding(boolean),并設(shè)置為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之前,它將改變陰影的大小。為了避免在陰影大小變化時(shí)移動(dòng)視圖,使用setMaxCardElevation()來限制影子大小。如果您想要?jiǎng)討B(tài)地更改海拔,您應(yīng)該在初始化CardView時(shí)調(diào)用@link setMaxCardElevation(float)。