Summarize the usage of the Material Design control cradview
This article mainly introduces the use of CardView. CardView inherits from FrameLayout,
It is easy to use. You only need to use CardView to include other views to achieve the card effect.
Add dependency Library
compile 'com.android.support:cardview-v7:22.2.0'
Use in Layout
<? 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/plugin" app: cardMaxElevation = "@ dimen/plugin"> <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 = "many things" android: textColor = "@ android: color/holo_green_dark"/> </LinearLayout> </android. support. v7.widget. cardView> </LinearLayout>
Where
- App: cardBackgroundColor sets the CardView background color
- App: cardCornerRadius: Set the CardView rounded corner size
- App: cardElevation sets the CardView shadow height
Running effect:
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.