Android Card_view 材料设计
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24994210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Card_view material design
提问by Jelleroggie
I am trying to use card_view
. But it keeps giving an error.
我正在尝试使用card_view
. 但是一直报错。
Error:(13) No resource identifier found for attribute `'cardCornerRadius' in package 'com.google.example.test_app'
错误:(13)在包“com.google.example.test_app”中找不到属性“cardCornerRadius”的资源标识符
<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>
What am I doing wrong here?
我在这里做错了什么?
回答by mindex
EDIT: This has been fixed in the Android 5.0 Lollipop SDK. Simply add
编辑:这已在 Android 5.0 Lollipop SDK 中修复。只需添加
compile 'com.android.support:cardview-v7:21.+'
to your build.gradle and you're good to go.
到您的 build.gradle,您就可以开始了。
OLD answer:
旧答案:
You'll need to add the cardview support library dependency to build.gradle:
您需要将 cardview 支持库依赖项添加到 build.gradle:
compile 'com.android.support:cardview-v7:21.+'
However, due to the way Google built the library, you'll also have to compile your app using the latest "L" SDK:
但是,由于 Google 构建库的方式,您还必须使用最新的“L”SDK 编译您的应用程序:
compileSdkVersion "android-L"
buildToolsVersion "20.0.0"
and
和
minSdkVersion 14
targetSdkVersion "L"
Note that the minSdkVersion here doesn't really matter - as long as you compile with "L" SDK, your app can only run on L device/emulator no matter what minSdkVersion is specified.
请注意,这里的 minSdkVersion 并不重要 - 只要您使用“L”SDK 进行编译,无论指定什么 minSdkVersion,您的应用程序都只能在 L 设备/模拟器上运行。
The only viable way to build with the cardview lib for earlier Android version seems to be using Eddie Ringle's workaround.
使用早期 Android 版本的 cardview lib 构建的唯一可行方法似乎是使用 Eddie Ringle 的解决方法。
See Failure [INSTALL_FAILED_OLDER_SDK] Android-Lfor some related info.
有关一些相关信息,请参阅失败 [INSTALL_FAILED_OLDER_SDK] Android-L。
回答by Akanksha Rathore
For eclipse We need to include both the things add android.support.v7.widget.CardView
as a library project and also add + check it's jar file in java build path
对于 eclipse 我们需要包含添加android.support.v7.widget.CardView
为库项目的东西,并在 java 构建路径中添加 + 检查它的 jar 文件
- Go to File -> Import -> Existing Android code into workspace --> Browse (Go to sdk/extras/android/support/v7/cardview) --> Click ok --> Click Finish
- Right click on cardview project --> Properties --> Android(Left Pane) --> Enable isLibrary (tick the checkbox) --> Apply --> ok
- Right click on your project --> Properties --> Android(Left pane) --> Add (under library) --> cardview --> apply --> ok
- Right click on your project again --> build path --> configure build path -->under libraries-->add jar-->expand cardview-->expand libs-->select android.support.v7.widget.CardView.jar
- 转至文件 -> 导入 -> 现有 Android 代码到工作区 --> 浏览(转至 sdk/extras/android/support/v7/cardview)--> 单击确定 --> 单击完成
- 右键单击cardview项目-->属性-->Android(左窗格)-->启用isLibrary(勾选复选框)-->应用-->确定
- 右键单击您的项目--> 属性--> Android(左窗格)--> 添加(在库下)--> cardview --> 应用--> 确定
- 再次右键单击您的项目--> 构建路径--> 配置构建路径--> 在库下--> 添加jar--> 扩展cardview--> 扩展libs--> 选择android.support.v7.widget.CardView 。罐
under order and export-->check android.support.v7.widget.CardView.jar-->click
在order和export-->勾选android.support.v7.widget.CardView.jar-->点击
Hope it will help someone.
希望它会帮助某人。
回答by Anilkumar
回答by Wendy Chen
I just resolved this problem by checking CardView project "Library Module" in Android Studio.
我刚刚通过在 Android Studio 中检查 CardView 项目“库模块”解决了这个问题。
回答by brazilianldsjaguar
For those of you coming in here looking for Xamarin-specific, once you've added the Android Support Library v7 CardViewcomponent, you need to Cleanyour project and then re-build.
对于来这里寻找特定于 Xamarin 的人,一旦添加了Android 支持库 v7 CardView组件,您需要清理您的项目,然后重新构建。