Android CardView use and import error issues

Source: Internet
Author: User

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, and another recyclerview at the same time.


Location in the Android SDK package, folder: ... \android-sdk-windows\extras\android\support\v7,


Assuming that you use Recyclerview in your own project, you will directly ... \android-sdk-windows\extras\android\support\v7\recyclerview\ The Android-support-v7-recyclerview.jar copy under the Libs package is available under the Libs folder of your project.
But CardView can't do that. Assuming that a jar package is copied just like Recyclerview, an error occurs and the CardView cannot be loaded.
The correct way to use Android CardView is:
(1) First the entire CardView folder under the \android-sdk-windows\extras\android\support\v7 folder 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>


Of
Card_view:cardcornerradius defines the fillet size.


Card_view:cardelevation defines the shadow size.


Test Mainactivity.java:

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);}}


Execution results

Android CardView use and import error issues

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.