我正在使用 Eclipse,但在使用 CardView
时遇到问题。
error: No resource identifier found for attribute 'cardCornerRadius' in package
我已经将最新的 android-support-v7-cardview.jar 添加到 libs 文件夹和构建路径。
我的CardView布局:
<RelativeLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".activity.CardViewActivity">
<android.support.v7.widget.CardView
android:layout_width="200dp"
android:layout_height="200dp"
android:id="@+id/cardView"
card_view:cardCornerRadius="6dp"
card_view:cardBackgroundColor="#84ffff">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test CardView"
android:layout_centerInParent="true"
android:textSize="18sp"
android:textColor="#fff"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
list 中的目标 sdk 版本也是 targetSdkVersion="22"
。
但我仍然遇到同样的错误。
请不要给我 Android Studio 的示例。在 AS 中运行良好。但由于很多原因我不使用它。
最佳答案
尝试这些(假设您已将 v7 支持库
jar 文件添加到 libs 文件夹
):
- 在新库项目中,展开
libs 文件夹
,右键单击 .jar 文件并选择构建 > 路径 > 添加到构建路径 - 右键单击库项目文件夹并选择构建路径>
配置构建路径。在
Order and Export
选项卡中,选中您添加到构建路径的.jar 文件
,以便将其导出到项目并取消选中 Android 依赖项
--
实现这一目标的其他方式
将其添加到样式
:
<style name="CardViewStyle" parent="MyCardView">
<item name="cardCornerRadius">6dp</item>
<item name="cardBackgroundColor">#84ffff</item>
</style>
并将CardView
的父属性设置为MyCardView
并从 xml
中删除这些行:
card_view:cardCornerRadius="6dp"
card_view:cardBackgroundColor="#84ffff"
--
另请检查您是否有:
- 最新
Android SDK 工具
、平台工具
和构建工具
- 最新
Android 支持库
关于Android CardView 和 Eclipse ADT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30208054/