android - Card_view Material 设计

标签 android android-layout android-5.0-lollipop android-cardview

我正在尝试使用 card_view。但是一直报错。

Error:(13) No resource identifier found for attribute `'cardCornerRadius' in package 'com.google.example.test_app'

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    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"
    android:background="#610B0B"
    tools:context=".MyActivity"
    android:id="@+id/myactivity ">
    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_gravity="center"
        android:background="#fff"
        card_view:cardCornerRadius="4dp">
        <TextView
        android:id="@+id/my_textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/next"
        android:background="#fff"
        android:elevation="5dp" />
    </android.support.v7.widget.CardView>
</RelativeLayout>

我在这里做错了什么?

最佳答案

编辑:这已在 Android 5.0 Lollipop SDK 中得到修复。只需添加

compile 'com.android.support:cardview-v7:21.+'

到您的 build.gradle ,一切顺利。

旧答案:

您需要将 cardview 支持库依赖项添加到 build.gradle:

compile 'com.android.support:cardview-v7:21.+'

但是,由于 Google 构建库的方式,您还必须使用最新的“L”SDK 编译您的应用:

compileSdkVersion "android-L"
buildToolsVersion "20.0.0"

minSdkVersion 14
targetSdkVersion "L"

请注意,这里的 minSdkVersion 并不重要 - 只要您使用“L” SDK 编译,无论指定什么 minSdkVersion,您的应用都只能在 L 设备/模拟器上运行。

使用 Cardview 库构建早期 Android 版本的唯一可行方法似乎是使用 Eddie Ringle 的 workaround .

Failure [INSTALL_FAILED_OLDER_SDK] Android-L获取一些相关信息。

关于android - Card_view Material 设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24994210/

相关文章:

android - Activity 转换 : Performing stop of activity that is not resumed

android - 如何在android中将字符串转换为标题大小写?

android - 在运行时设置 Activity 的屏幕方向时遇到困难

android - 如何在android中创建一个可点击的不规则形状区域?

android - 合并标签的使用

安卓无界波纹和背景

android - 错误:Module version com. loopj.android :android-async-http:1. 4.3依赖于库但本身不是库

c# - Retrofit + Restful c# 上传文件

java - Firestore 根据喜欢来订购集合

Android 文本文件(在原始目录中)未被正确读取