compile 'com.android.support:cardview-v7:21.0.+'
app:cardElevation 屬性向下兼容 為了統一不同系統版本的視覺效果,Google 針對 SDK 21 以下的系統給 CardView 加入一個 Elevation 兼容(即 XML 中的 app:cardElevation 和 Java 代碼中的 setCardElevation)。
attr name="cardBackgroundColor" format="color" ?背景顏色
attr name="cardCornerRadius" format="color" ?圓角半徑
attr name="cardElevation" format="dimension" 海拔(z軸) 陰影的大小
attr name="cardMaxElevation" format="dimension" 最大仰角,陰影最大高度
attr name="cardUseCompatPadding" format="boolean" 設置內邊距,V21+的版本和之前的版本仍舊具有一樣的計算方式
attr name="cardPreventCornerOverlap" format="boolean" 是否添加內邊距(避免內容與邊緣重疊)
attr name="contentPadding" format="dimension" 邊距
◆ 為你的 Card 添加點擊效果
當使用 CardView 的場合是作為列表中的一個 Item 且直接單擊 Item 有相應的操作,那么就有必要加上視覺反饋來告訴用戶這個 Card 是可點擊的。
如果你是用了 AppCompat v7 支持庫:
那么你可以直接給 CardView 加上android:foreground="?attr/selectableItemBackground" 這個屬性會在 Lollipop 上自動加上 Ripple 效果,在舊版本則是一個變深/變亮的效果。