Android MD之CardView

從Android5.0開始,google引入了Material Design,那么我們今天就來講講CardView

首先要明白CardView能夠帶來哪些效果:

1、四周陰影效果

2、四周圓角效果

下面看張圖片:

cardView顯示效果

要想實現如上cardView顯示效果,分以下步驟:

1、引入庫,在android studio中導入v7兼容包:

compile'com.android.support:cardview-v7:23.1.1'//cardview

2、在布局文件中加入cardview

布局中加入CardView

注意CardView和Scroview一樣僅允許有一個孩子view,你懂得

3、注意到上面有兩個屬性

app:cardElevation 和? card_view:cardBackgroundColor,使用這兩個屬性時需要在xml中引入以下schemas:

引入schemas

4、關于各個屬性介紹

android:cardCornerRadius ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?在xml文件中設置card圓角的大小

CardView.setRadius ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?在代碼中設置card圓角的大小

android:cardBackgroundColor ? ? ? ? ? ? ? ? ? ? ? ? ? ?在xml文件中設置card背景顏色

android:elevation ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??在xml文件中設置陰影的大小

card_view:cardElevation ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??在xml文件中設置陰影的大小

card_view:cardMaxElevation ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?在xml文件中設置陰影最大高度

card_view:cardCornerRadius ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??在xml文件中設置卡片的圓角大小

card_view:contentPadding ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?在xml文件中設置卡片內容于邊距的間隔

card_view:contentPaddingBottom ? ? ? ? ? ? ? ? ? ? ??在xml文件中設置卡片內容于下邊距的間隔

card_view:contentPaddingTop ? ? ? ? ? ? ? ? ? ? ? ? ? ??在xml文件中設置卡片內容于上邊距的間隔

card_view:contentPaddingLeft ? ? ? ? ? ? ? ? ? ? ? ? ? ??在xml文件中設置卡片內容于左邊距的間隔

card_view:contentPaddingRight ? ? ? ? ? ? ? ? ? ? ? ? ?在xml文件中設置卡片內容于右邊距的間隔

card_view:contentPaddingStart ? ? ? ? ? ? ? ? ? ? ? ? ??在xml文件中設置卡片內容于邊距的間隔起始

card_view:contentPaddingEnd ? ? ? ? ? ? ? ? ? ? ? ? ??在xml文件中設置卡片內容于邊距的間隔終止

card_view:cardUseCompatPadding ? ? ? ? ? ? ? ? ?在xml文件中設置內邊距,V21+的版本和之前的版本仍舊具有一樣的計算方式

card_view:cardPreventConrerOverlap ? ? ? ? ? ? ??在xml文件中設置內邊距,在V20和之前的版本中添加內邊距,這個屬性為了防止內容和邊角的重疊

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容