Android 5.0 new features CardView tutorial

Source: Internet
Author: User

CardView is android5.0 New added features , we first don't worry, because Google out of the CardView Compatibility Pack, That is 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:


 < xmlns:card_view= "Http://" 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> </>

Implementation results:


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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.