Android CardView details and use methods and examples _android

Source: Internet
Author: User

Android CardView Detailed

Android5.0 introduces us to a completely new control –cardview, which, in essence, can be seen as framelayout adding rounded corners and shadow effects on top of itself. Please note that the CardView is packaged as a layout and is often used as a container in the item layout of ListView and Recyclerview.

Found a good-looking dongdong cardview, he in support V7 bag ~ ~

As the name suggests is the card view, you can set shadows, rounded corners, and so on.

Looks like this:

Or you can put it in the ListView:

How to use

Secondly, it introduces its basic properties:

App:cardbackgroundcolor This is setting the background color
App:cardcornerradius this is to set fillet size
App:cardelevation This is the shadow that sets the Z axis
App:cardmaxelevation This is the maximum height value of the z axis set
App:cardusecompatpadding whether to use compatpadding
App:cardpreventcorneroverlap whether to use Preventcorneroverlap
App:contentpadding Set the content padding
App:contentpaddingleft set the left padding of content
App:contentpaddingtop set content on padding
App:contentpaddingright set the right padding of the content
App:contentpaddingbottom set the bottom of the content padding

Add a CardView to the XML file

 <android.support.v7.widget.cardview xmlns:card_view= "Http://schemas.android.com/apk/res-auto"
    android: Layout_width= "200DP"
    android:layout_height= "wrap_content"
    <--! set CardView background color-->
    Card_view: Cardbackgroundcolor= "#303069"

    <--! set CardView radius-->
    card_view:cardcornerradius= "10DP"
    card_ View:cardpreventcorneroverlap= "true"
    card_view:cardusecompatpadding= "true"

    <--! setting CardView padding-- >
    card_view:contentpadding= "10DP" >
    <textview
      android:text= "I am CardView"

      android: Textcolor= "#fff"
      android:layout_width= "wrap_content"
      android:layout_height= "wrap_content"/>

  </android.support.v7.widget.CardView>

Inside can wrap content, through observation source code we found that CardView is actually a framelayout, so use the same way as Framelayout

public class CardView extends Framelayout implements Cardviewdelegate {
}

Or you can also be used for listview~~ anyway very simple beautiful is AH ~ ~

In the future meet what fillet demand, you can use this to complete, and not what Porterduffxfermode ~ ~

Thank you for reading, I hope to help you, thank you for your support for this site!

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: info-contact@alibabacloud.com 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.