Android CardView 和 Eclipse ADT
Android CardView And Eclipse ADT
我正在使用 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>
清单中的目标 sdk 版本也是 targetSdkVersion="22"
。
但我仍然得到同样的错误。
请不要给我 Android Studio 的示例。它在 AS 中运行良好。但是因为很多原因我没有使用它。
尝试这些(假设您已将 v7 support library
jar 文件 添加到 libs folder
):
- 在新建库项目中,展开
libs folder
,右键.jar文件和select Build > Path >添加到构建路径
- 右键单击 库项目文件夹和 select Build Path >
配置构建路径。在
Order and Export
选项卡中,选中您添加到构建路径的 .jar file
,以便将其导出到项目并 取消选中 Android Dependencies
--
其他实现方式
将此添加到 styles
:
<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 Tools
、Platform-tools
和 Build-tools
- 最新
Android Support Library
终于找到解决办法了。而不是添加 .jar 文件。您可以将其导入为库。
Error inflating class and android.support.v7.widget.CardView
我正在使用 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>
清单中的目标 sdk 版本也是 targetSdkVersion="22"
。
但我仍然得到同样的错误。
请不要给我 Android Studio 的示例。它在 AS 中运行良好。但是因为很多原因我没有使用它。
尝试这些(假设您已将 v7 support library
jar 文件 添加到 libs folder
):
- 在新建库项目中,展开
libs folder
,右键.jar文件和select Build > Path >添加到构建路径 - 右键单击 库项目文件夹和 select Build Path >
配置构建路径。在
Order and Export
选项卡中,选中您添加到构建路径的.jar file
,以便将其导出到项目并 取消选中 Android Dependencies
--
其他实现方式
将此添加到 styles
:
<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 Tools
、Platform-tools
和Build-tools
- 最新
Android Support Library
终于找到解决办法了。而不是添加 .jar 文件。您可以将其导入为库。
Error inflating class and android.support.v7.widget.CardView