Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble importing android.support.v7.widget.CardView into Eclipse

I use Eclipse and I'm trying to create an application using the new support-library-v7:21.+ from Lollipop.

  • Created my new project
  • imported in eclipse the support-library-v7
  • changed in project-properties of support library the line: target=android-21 with 21 target
  • changed the target of my application in 21
  • imported the library in my project
  • clean all

After all i still got the invalid R declaration. I restarted Eclipse and then, after re-importing the library, seem went! I created a Tolbar and a NavigationDrawer as well without problem - it works.

Now, i would like to put a CardView in my ListView items:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
   >
    <!-- A CardView that contains a TextView -->
    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_gravity="center"
        android:layout_width="200dp"
        android:layout_height="200dp"
        card_view:cardCornerRadius="4dp">
    <TextView
        android:id="@+id/name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <TextView
        android:id="@+id/codename"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <TextView
        android:id="@+id/versione"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <TextView
        android:id="@+id/link"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <TextView
        android:id="@+id/timestamp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

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

well, first error: No resource identifier found for attribute 'cardCornerRadius'. I tried to delete the attribute, restart the application but I get a the following crash:

java.lang.RuntimeException: Binary XML file line #2: You must supply a layout_width attribute.

I don't understand what the problem is.

like image 510
Atlas91 Avatar asked Nov 03 '14 17:11

Atlas91


1 Answers

Adding the library

Gradle

compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:cardview-v7:22.0.0'

Eclipse

Using android.support.v7.widget.CardView in my project (Eclipse)

Proper LinearLayout

As the error said, a LinearLayout needs a layout_width and a layout_heighth. Always.

like image 101
shkschneider Avatar answered Nov 02 '22 06:11

shkschneider