2015-08-13 83 views
8

我正在学习Android材质设计,但在两者之间它一直给出错误。谁可以帮我这个事?cardCornerRadius显示错误

workspace/RecyclerCardView/res/layout/list_item_row.xml:2: error: No resource identifier found for attribute 'cardCornerRadius' in package 'com.Zybo.recyclercardview'

<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:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_margin="5dp" 
card_view:cardCornerRadius="5dp" > 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/img_id" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="7dp" /> 

    <TextView 
     android:id="@+id/txt_id" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hellooo..." /> 
</LinearLayout> 

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

确保你已经添加V7支持库 –

+0

我已经创建了一个单独的库,其中包含卡视图和回收视图类,并添加了该项目作为支持库。我还在build.gradle文件中添加了依赖关系。 – Ramz

回答

4

感谢所有试图解决的问题。 最后我得到了我的问题的答案:

  1. 导入卡片视图和sdk/extras/v7/cardview
  2. sdk/extras/v7/recycleview
  3. 单独回收视图右键单击导入的项目去属性和检查库复选框。
  4. 现在转到您正在工作的主项目并通过右键单击项目添加这两个库转至属性 - > android(左侧) - >单击添加(库)(右下侧)和所需的库。
+0

谢谢!我虽然它受到支持设计。是的,我们需要添加cardview和recycleview的依赖关系。 compile'c​​om.android.support:design:23.4.0' compile'c​​om.android.support:recyclerview-v7:23.4.0' compile'c​​om.android.support:cardview-v7:23.4.0' –

3

使用本

<android.support.v7.widget.CardView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:cardCornerRadius="10dp" 
     > 
+0

Iam sry说,即使上面的代码不起作用。 – Ramz

20
compile 'com.android.support:cardview-v7:24.2.1' 
compile 'com.android.support:appcompat-v7:24.2.1' 
compile 'com.android.support:design:24.2.1' 

以上就足够了。

+1

这工作。增加了对build.gradle文件的卡片视图包支持 –

6

这为我工作

app:cardCornerRadius="5dp" 
app:cardElevation="2dp" 
4

添加这些依赖关系的build.gradle。
使用关键字执行,而不是编译,因为它已经被废弃了

实行“com.android.support:cardview-v7:26.1.0”
实行“com.android.support:appcompat-v7:26.1.0”

然后用
应用:cardCornerRadius = “5DP”

,而不是
card_view:cardCornerRadius = “5DP”