Ym--android 5.0 Study of CardView

Source: Internet
Author: User

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

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: 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.