【问题标题】:Android CardView And Eclipse ADTAndroid CardView 和 Eclipse ADT
【发布时间】:2015-11-20 17:02:13
【问题描述】:

我正在使用 Eclipse,但遇到CardView 的问题。

错误:在包中找不到属性“cardCornerRadius”的资源标识符

我已经将最新的 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 中运行良好。但我不使用它有很多原因。

【问题讨论】:

  • 你检查过这个link 吗?
  • @hrskrs,当然可以。但正如你所见,它需要 AS(1. 在 Android Studio 中创建一个新项目)。但这对我来说现在是不可能的。

标签: android android-support-library eclipse-adt android-cardview


【解决方案1】:

试试这些(假设你已经将v7 support libraryjar 文件添加到libs folder):

  • 在新的库项目中,展开libs folder右击.jar文件并选择Build > Path > Add to 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 ToolsPlatform-toolsBuild-tools
  • 最新Android Support Library

【讨论】:

  • 谢谢。但是当我开始项目时,它再次显示相同的错误“没有为包中的属性 'cardCornerRadius' 找到资源标识符”。
  • @Sever 你可以试试我的第二个建议,我编辑了我的答案,以实现你想要的行为
  • 再次感谢您。但是再次“找不到与给定名称匹配的资源:attr 'cardCornerRadius'”
【解决方案2】:

终于找到了解决办法。而不是添加 .jar 文件。您可以将其作为库导入。

Error inflating class and android.support.v7.widget.CardView

【讨论】:

  • 是的。您应该将其作为库导入。库项目有资源不能包含在 jar 中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-09-05
  • 1970-01-01
  • 2015-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-09
相关资源
最近更新 更多