標(biāo)題: 商城開發(fā)筆記-05-CardView的基本使用 [打印本頁(yè)]
作者: 51黑bing 時(shí)間: 2016-3-22 17:19
標(biāo)題: 商城開發(fā)筆記-05-CardView的基本使用
一、CardView的簡(jiǎn)介
CardView繼承自FrameLayout類,可以在一個(gè)卡片布局中一致性的顯示內(nèi)容,卡片可以包含圓角和陰影,這是CardView的最大的賣點(diǎn)。CardView是一個(gè)Layout,可以布局其他View。
CardView常用屬性:
card_view:cardElevation 陰影的大小
card_view:cardMaxElevation陰影最大高度
card_view:cardBackgroundColor卡片的背景色
card_view:cardCornerRadius卡片的圓角大小
card_view:contentPadding卡片內(nèi)容于邊距的間隔
card_view:contentPaddingBottom
card_view:contentPaddingTop
card_view:contentPaddingLeft
card_view:contentPaddingRight
card_view:contentPaddingStart
card_view:contentPaddingEnd
card_view:cardUseCompatPadding設(shè)置內(nèi)邊距,V21+的版本和之前的版本仍舊具有一樣的計(jì)算方式
card_view:cardPreventConrerOverlap在V20和之前的版本中添加內(nèi)邊距,這個(gè)屬性為了防止內(nèi)容和邊角的重疊
二、CardView的基本使用
1、在Gradle中引入CardView的依賴庫(kù)。
compile 'com.android.support:cardview-v7:23.1.1'
2、在布局文件當(dāng)中放置我們的CardView。CardView里面也可以放置任意控件以及布局容器,注意要給CardView設(shè)置命名空間以及它的常用屬性。有一些屬性也可以在代碼當(dāng)中設(shè)置,這里不再贅述了。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
card_view:cardBackgroundColor="#303069"
card_view:cardCornerRadius="10dp"
card_view:cardElevation="5dp"
card_view:cardMaxElevation="7dp"
card_view:cardPreventCornerOverlap="true"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="10dp">
<TextView
android:id="@+id/tv_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Card很漂亮"/>
</android.support.v7.widget.CardView>
三、運(yùn)行效果
楠妹妹是直接在上一個(gè)例子的條目中使用CardView的。CardView的使用比較簡(jiǎn)單,今天的筆記就先到這里告一段落了。
歡迎光臨 (http://www.torrancerestoration.com/bbs/) |
Powered by Discuz! X3.1 |