Objective
CardView, as the name implies, is a card-like control, :
Before Android 5.0, we had two options to make this happen:
1. By setting the background map
2. Set Configuration shape file
And now we need to trouble art mm, also do not need to configure the trouble of shape file, just need to set a few properties, it is to use our CardView
CardView
CardView inherits the Framelayout class and gives you the appearance of cross-platform consistency in the cards inside. CardView controls can have shadows and rounded corners (effects).
To create a card with a shadow effect, you can use the Card_view:cardelevation property. CardView will use real elevation (elevation) and dynamic shading in systems above Android5.0 (API level 21), and (while) will fall back to the procedural shadow effect display in lower system versions. For more information, see Maintaining compatibility (Maintain compatibility).
Use these properties to customize the appearance of the CardView control:
Set the fillet radius in the layout, using the Card_view:cardcornerradius property
Set the fillet radius in your code, using the Cardview.setradius method
To set the background color of a card, use the Card_view:cardbackgroundcolor property
In order to make everyone better understand and use the knowledge point that I speak, this time CardView as item added to Recyclerview .
Steps to use:
1. Import /sdk/extras/android/support/v7/cardview/libs/android-support-v7-cardview.jar
2. refer the/sdk/extras/android/support/v7/cardview as a library project to the project
3. Modify the layout of the next item
The original XML
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/ Res/android " xmlns:tools=" Http://schemas.android.com/tools " android:orientation=" Horizontal " Android:layout_width= "Match_parent" android:layout_height= "match_parent" > <textview Android:id= "@+id/textviewsample" android:layout_width= "0DP" android:layout_height= "Wrap_content " android:layout_weight= "1" android:textsize= "20sp" android:padding= "30DP" android:fontfamily= " Sans-serif-light " tools:text=" Sample text " /></linearlayout>
The modified XML
<?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 : id= "@+id/card_view" android:layout_width= "match_parent" android:layout_height= "Match_parent " android:layout_margin= "5DP" > <textview android:id= "@+id/textviewsample" android:layout_width = "0DP" android:layout_height= "wrap_content" android:layout_weight= "1" android:fontfamily= " Sans-serif-light " android:padding=" 30DP " android:textsize=" 20SP "/></ Android.support.v7.widget.cardview>
Oh, ~! Feel to try it ~!
Ym--android 5.0 Study of CardView