CardView is android5.0 New added features , we first don't worry, because Google out of the CardView Compatibility Pack, That is Android.support.v7.widget.CardView package, so the system under 5.0 can also run this effect. What is CardView? is to add a shadow like a card to the outside of the view and put the code below.
<relativelayout android:layout_width= "match_parent" android:layout_height= "Wrap_content " android:padding= "5DP" > <imageview android:id= "@+id/pic" android:layout_width= "Match_parent" android:layout_height= "wrap_content" android:scaletype= "Centercrop"/> <textview Android:id= "@+id/name" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:layout_below= "@id/pic" android:layout_centerhorizontal= "true" android:gravity= "center" android:textcolor= "#212121" android:textsize= "16sp"/> </RelativeLayout>
This is the original code. Here's how it works:
Then, just add a few lines of code on the Relativelayout line, and you'll be able to practice the card effect:
Code
<android.support.v7.widget.cardview xmlns:card_view= "Http://schemas.android.com/apk/res-auto" Android:la Yout_width= "Match_parent" android:layout_height= "match_parent" android:layout_margin= "5DP" Card_view: Cardbackgroundcolor= "@color/cardview_light_background" card_view:cardcornerradius= "1DP" > <relativelay Out android:layout_width= "match_parent" android:layout_height= "Wrap_content" Android:padd ing= "5DP" > <imageview android:id= "@+id/pic" android:layout_width= "Match_pa Rent "android:layout_height=" wrap_content "android:scaletype=" Centercrop "/> & Lt TextView android:id= "@+id/name" android:layout_width= "Wrap_content" android:l ayout_height= "Wrap_content" android:layout_below= "@id/pic" android:layout_centerhorizontal= " Trueandroid:gravity= "center" android:textcolor= "#212121" android:textsize= "16sp"/> &L T;/relativelayout> </android.support.v7.widget.CardView>
Implementation results:
which
Card_view:cardcornerradius= "1DP" is to set the fillet effect.
As a comparison, we change to
Card_view:cardcornerradius= "10DP" look
Here are the following:
The rounded corners are obviously getting bigger.
Android 5.0 new features CardView tutorial