Damn app crashes, finally solved error-while-inflating-CardView
Preface (First, a smiley face) This problem has been bothering me for a long time. I searched all over with no results. The solutions I got were nothing more than that the AppCompact and CardView package versions were different, and so on, but I didn't have that problem at all. (Afraid they don't take my Gradle seriously?) Problem It's this kind of interface, using RecycleView and Cardview, but it doesn't work on SDK 23 and below. Official docs already state this component is supported down to SDK 9 or 10, anyway basically any android phone can
目录3 个章节
Preface
(First, a smiley face) This problem has been bothering me for a long time. I searched all over with no results. The solutions I got were nothing more than that the AppCompact and CardView package versions were different, and so on, but I didn't have that problem at all. (Afraid they don't take my Gradle seriously?)
Problem

It's this kind of interface, using RecycleView and Cardview, but it doesn't work on SDK 23 and below. Official docs already state this component is supported down to SDK 9 or 10, anyway basically any android phone should work, yet it just doesn't. On SDK 24 and above there's no problem, my own phone has no problem, it's just on the emulator and a few old-version test devices, they all crash. I really want to strangle this Cardview..
Solution
Tonight I spent two hours looking things up, went through Google's official docs, downloaded a few official Samples, but didn't find any valuable solutions. Then I continued searching on Stack Overflow. Stack Overflow is really a programmer's essential helper for home and travel. Finally, hard work paid off, and I found fellow users who encountered the same problem as me.
These two answers were of reference value:
Try this it will help you remove this android:foreground="?android:attr/selectableItemBackground"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:paddingBottom="2dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cardview"
card_view:cardBackgroundColor="@android:color/white"
card_view:cardElevation="2dp"
card_view:cardMaxElevation="2dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
....here i have a bunch of other layout elements
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
This answer told me to delete android:foreground. I deleted it as instructed, but it still didn't work. However, using this on SDK 23 and below indeed has compatibility issues.
Then this one: https://stackoverflow.com/questions/28541920/error-when-inflating-cardview
From the official notes of appcompat v21
He told me to take a look at the official docs:
Why are there no ripples on pre-Lollipop? A lot of what allows RippleDrawable to run smoothly is Android 5.0’s new RenderThread. To optimize for performance on previous versions of Android, we've left RippleDrawable out for now.
When trying to use ripple-drawables, you get errors on pre-lollipop (that's why it says line 2, it's the xml drawable). Use a different folder (drawable-v21) for ripples and use selectors in your normal drawables if you want a difference for different states.
Official support is not coming soon, I believe, because lollipop has a dedicated render-thread that no other version has.
Meaning that android:stateListAnimator="@drawable/selector_elevation" doesn't work, it's not supported on older versions of the system..
And then new support is still coming soon? I don't believe it.
So in the end, I deleted both of these lines of code, and a touching scene appeared, it finally worked~~~ The deleted code, shit!
android:stateListAnimator="@drawable/selector_elevation"
android:foreground="?android:attr/selectableItemBackground"
_EOF_
Damn app crashes, finally solved error-while-inflating-CardView
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
Android开发:使用CardView实现卡片式设计
开头引用一段官网的介绍 A FrameLayout with a rounded corner background and shadow. CardView uses elevation property on Lollipop for shadows and falls back to a custom emulated shadow implementation on older platf
2021-12-18 · Android开发 · 约 1 分钟
Android-Studio-插件记录
GsonFormat https://blog.csdn.net/leejizhou/article/details/50557786 ButterKnifeZelezny http://blog.csdn.net/leejizhou/article/details/50541356 SQLScout SQLite调试神器。 http://www.idescout.com/ https://plu
2021-12-18 · Android开发 · 约 1 分钟
Android开发:解决在Linux上提示-dev-kvm-device-permission-denied问题
操作步骤 我用的是Ubuntu系统,首先需要安装qemu-kvm: sudo apt install qemu-kvm 将当前用户添加到kvm用户组: sudo adduser $USER kvm 检查/dev/kvm所有者: ls -al /dev/kvm 一般结果就是所有者是root以及kvm这个组 添加完了之后检查一下kvm组里有没有你的用户名: grep kvm /etc/group 一般
2021-12-18 · Android开发 · 约 1 分钟
Android-ORM-框架:GreenDao入门
GreenDao 简介 GreenDAO 是一款开源的面向 Android 的轻便、快捷的 ORM 框架,将 Java 对象映射到 SQLite 数据库中,我们操作数据库的时候,不在需要编写复杂的 SQL语句, 在性能方面,GreenDAO 针对 Android 进行了高度优化, 最小的内存开销 、依赖体积小 同时还是支持数据库加密。 GreenDAO 官网地址:http://greenrobot
2022-05-27 · Android开发 · 约 1 分钟
讨论
共 0 条加载评论中…