compile 'com.android.support:cardview-v7:21.0.+'```
- 創(chuàng)建卡片
[CardView](https://developer.android.com/reference/android/support/v7/widget/CardView.html)
擴展 [FrameLayout](https://developer.android.com/reference/android/widget/FrameLayout.html)類別并讓您能夠顯示卡片內(nèi)的信息,這些信息在整個平臺中擁有一致的呈現(xiàn)方式。
[CardView](https://developer.android.com/reference/android/support/v7/widget/CardView.html)小組件可擁有陰影和圓角。
如果要使用陰影創(chuàng)建卡片,請使用 card_view:cardElevation屬性。
[CardView](https://developer.android.com/reference/android/support/v7/widget/CardView.html)在 Android 5.0(API 級別 21)及更高版本中使用真實高度與動態(tài)陰影,而在早期的 Android 版本中則返回編程陰影實現(xiàn)。如需了解詳細信息,請參閱[保持兼容性](https://developer.android.com/training/material/compatibility.html)
使用這些屬性定制 [CardView](https://developer.android.com/reference/android/support/v7/widget/CardView.html)
小組件的外觀:
如果要在您的布局中設(shè)置圓角半徑,請使用 card_view:cardCornerRadius屬性。
如果要在您的代碼中設(shè)置圓角半徑,請使用 CardView.setRadius方法。
如果要設(shè)置卡片的背景顏色,請使用 card_view:cardBackgroundColor屬性。
下列代碼示例將展示如何將 [CardView](https://developer.android.com/reference/android/support/v7/widget/CardView.html)
小組件包括在您的布局中:
```xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto" ... >
<!-- A CardView that contains a TextView -->
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp"
card_view:cardCornerRadius="4dp">
<TextView
android:id="@+id/info_text"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v7.widget.CardView>
</LinearLayout>```
注:以上部分大多翻譯自google的官網(wǎng),為了沒梯子的同志們著想,搬過來。
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。