【发布时间】:2015-04-30 01:12:01
【问题描述】:
我在我的项目中使用 CardView,但在旧设备上出现错误:
E android.view.InflateException: Binary XML file line #25: Error inflating class android.support.v7.widget.CardView
E at android.view.LayoutInflater.createView(LayoutInflater.java:518)
E at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
E at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
E at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
E at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
E at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
似乎类似于一些关于 SO 的问题,例如this one
我的问题是,这些问题的解决方案让人感觉很老套,这是可以理解的,因为去年 Lollipop 刚刚进入公共预览版时就给出了答案。从那以后情况有变化吗?我如何获得资源?
我尝试了一些方法,例如将 .aar 作为模块导入,但似乎没有任何效果。我遵循了有关如何添加支持库 (https://developer.android.com/tools/support-library/setup.html#libs-with-res) 的官方文档,但这没有用。同样根据该链接-为Android Studio添加带有和不带有资源的库似乎没有任何区别?
我的应用 build.gradle 包含以下依赖项:
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'
这里使用 CardView 布局
<android.support.v7.widget.CardView
xmlns:card="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground"
card:cardCornerRadius="6dp"
card:cardUseCompatPadding="true"
tools:ignore="NewApi">
编辑:三星 S2 2.3 上发现的问题 - API 19+ 工作正常
【问题讨论】:
-
也分享xml代码
-
为我的卡片视图添加了 xml
-
这是您的 xml 中的第 25 行
-
这是卡片视图的行
-
奇怪的问题帮不上忙,只要确保你也更新了 v4 库
标签: android android-appcompat android-cardview