總結一下 Material Design控制項 cradview 的用法,designcradview
本文主要介紹CardView的使用,CardView是繼承自FrameLayout,
使用比較簡單,只需要用CardView包含其他View就可以實現卡片效果了。
加入依賴庫
compile 'com.android.support:cardview-v7:22.2.0'
在布局中使用
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" app:cardElevation="@dimen/cardview_compat_inset_shadow" app:cardCornerRadius="@dimen/cardview_default_radius" app:cardMaxElevation="@dimen/cardview_default_elevation" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="20dp"> <TextView android:id="@+id/textview1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/trytry" android:textColor="@android:color/holo_blue_dark" android:textSize="25dp" /> <TextView android:id="@+id/desc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="好多東西" android:textColor="@android:color/holo_green_dark" /> </LinearLayout> </android.support.v7.widget.CardView></LinearLayout>
其中
- app:cardBackgroundColor 設定CardView背景顏色
- app:cardCornerRadius 設定CardView圓角大小
- app:cardElevation 設定CardView陰影高度
運行效果:
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。