CardView

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)。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Material Design中有一種很個(gè)性的設(shè)計(jì)概念:卡片式設(shè)計(jì)(Cards),Cards擁有自己獨(dú)特的UI特征...
    小莊bb閱讀 3,127評論 1 4
  • Material design中有一種很個(gè)性的設(shè)計(jì)概念:卡片式設(shè)計(jì)(Cards),這種設(shè)計(jì)與傳統(tǒng)的List Ite...
    亦楓閱讀 8,701評論 6 44
  • Material Design中有一種很個(gè)性的設(shè)計(jì)概念:卡片式設(shè)計(jì)(Cards),Cards擁有自己獨(dú)特的UI特征...
    滴滴滴9527閱讀 45,924評論 3 64
  • CardView 擴(kuò)展 FrameLayout 類并讓您能夠顯示卡片內(nèi)的信息,這些信息在整個(gè)平臺(tái)中擁有一致的呈現(xiàn)方...
    輕云時(shí)解被占用了閱讀 7,157評論 4 22
  • 秋日的雨一下就是一兩天,友約我在雨后的黃昏去老家走走,去看看路兩旁盛開的小花,青翠的風(fēng)景樹,或許還會(huì)有婆娑的楊柳。...
    秋之語閱讀 403評論 0 3

友情鏈接更多精彩內(nèi)容