標籤:div cardview iss tree eve nbsp 技術分享 ref 技術
CardView是Android 5.0新特性——Material Design中的一個布局控制項,可以通過屬性設定顯示一個圓角的類似卡片的視圖。
1、CardView的屬性:
app:cardCornerRadius:CardView的圓角大小 app:cardElevation:CardView的陰影大小 app:cardMaxElevation:CardView最大陰影大小 app:cardPreventCornerOverlap:CardView中的內容是否和圓角重疊,true為不重疊 註:如果CardView中有一張填充布局的圖片,則如果不設定cardPreventCornerOverlap為true的話,圖片的四個角 會延伸到CardView的圓角之外
2、示範代碼:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="200.0dip" android:layout_margin="20.0dip" app:cardCornerRadius="10.0dip" app:cardElevation="5.0dip" app:cardMaxElevation="15.0dip" app:cardPreventCornerOverlap="true"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:contentDescription="@string/app_name" android:scaleType="centerCrop" android:src="@mipmap/bg" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="THIS IS A CARDVIEW" android:textColor="#FFFFFFFF" android:textSize="24.0sp" android:textStyle="bold" /> </android.support.v7.widget.CardView></RelativeLayout>
運行結果:
以上就是對CardView簡單使用方法的介紹,下面貼出碼雲上的源碼,供大家參考。
DEMO地址
【Android - MD】之CardView的使用