Android CardView use and import error issues
The first part: The problem of importing Android CardView error.
Android CardView is a view component of Android in the Support.v7 package, along with a recyclerview.
Location in the SDK package for Android, directory: ... \android-sdk-windows\extras\android\support\v7,
If you are using Recyclerview in your own project, simply ... \android-sdk-windows\extras\android\support\v7\recyclerview\ The Android-support-v7-recyclerview.jar under the Libs package can be copied to the Libs directory of your project.
But CardView can't do that, if you just copy a jar package like Recyclerview, an error occurs and the CardView cannot be loaded.
The correct way to use Android CardView is:
(1) First the entire CardView directory under the \android-sdk-windows\extras\android\support\v7 directory as an Android Lib library, first imported into eclipse,
After importing to eclipse, check the is Library,
(2) Then add this CardView library in your own project,
The second part, the use of Android CardView.
After you import the CardView in the SUPPORT.V7 package correctly, you can use it directly. Android CardView is used like other Android view, and is used directly in the layout file, Card_view.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" card _view:cardbackgroundcolor= "@android: Color/white" card_view:cardcornerradius= "15DP" Card_view: cardelevation= "20DP" > <textview android:id= "@+id/text" android:layout_width= "Match_parent" android:layout_height= "match_parent" android:layout_gravity= "center" android:gravity= "center"/ ></android.support.v7.widget.CardView>
which
Card_view:cardcornerradius defines the fillet size.
Card_view:cardelevation defines the shadow size.
Mainactivity.java of the test:
Package Zhangphil.cards;import Android.app.listactivity;import Android.os.bundle;import Android.widget.arrayadapter;import Android.widget.listview;public class Mainactivity extends ListActivity {@ overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); ListView LV = This.getlistview (); string[] data = new String[50];for (int i = 0; i < data.length; i++) {Data[i] = "data" + I;} arrayadapter<string> adapter = new Arrayadapter<string> (This,r.layout.card_view, R.id.text, data); Lv.setadapter (adapter);}}
Run results
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. Reprint Please specify source: Http://blog.csdn.net/zhangphil
Android CardView use and import error issues