gpt4 book ai didi

android - 在使用 android 4.4 的 android 设备上将 CardView 膨胀到 Recyclerview 时发生 InflateException

转载 作者:行者123 更新时间:2023-11-30 00:08:26 26 4
gpt4 key购买 nike

当我尝试在版本 4.4 的 Android 设备上膨胀 CardView/RecyclerView 时,我遇到了这个 InflateException 请注意,我在版本超过 4.4 或 Kitkat 的任何设备上都没有遇到这个问题。

请问是异常的stacktrace

02-02 01:59:10.526 2288-2288/app.learnkannada.com.learnkannadakannadakali E/AndroidRuntime: FATAL EXCEPTION: main
Process: app.learnkannada.com.learnkannadakannadakali, PID: 2288
android.view.InflateException: Binary XML file line #0: Error inflating class android.support.v7.widget.CardView
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at adapter.ListViewAdapter.onCreateViewHolder(ListViewAdapter.java:68)
at adapter.ListViewAdapter.onCreateViewHolder(ListViewAdapter.java:28)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6365)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5563)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5448)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5444)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2224)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1551)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1511)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:595)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3600)
at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3036)
at android.view.View.measure(View.java:16497)
at android.widget.RelativeLayout.measureChild(RelativeLayout.java:689)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:473)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:393)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
at android.view.View.measure(View.java:16497)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1109)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang

难道Kitkat不支持RecyclerView/CardView?还是其他什么原因?请帮忙。

下面是发生异常的代码

 LayoutInflater inflater = LayoutInflater.from(parent.getContext());
v = inflater.inflate(R.layout.row_layout_course, parent, false);

下面是我要膨胀的 xml。

please find below is the xml code.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">

<android.support.v7.widget.CardView
android:foreground="?android:attr/selectableItemBackgroundBorderless"
app:cardCornerRadius="10dp"
android:layout_width="match_parent"
android:layout_margin="@dimen/cardview_compat_inset_shadow"
android:layout_height="wrap_content"
tools:targetApi="lollipop">

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:gravity="center_vertical"
android:padding="10dp"
android:layout_height="70dp">

<LinearLayout
android:orientation="vertical"
android:layout_weight="0.9"
android:layout_width="wrap_content"
android:paddingLeft="7dp"
android:layout_height="wrap_content">

<TextView
android:id="@+id/textID"
android:text="Test Text"
android:textStyle="bold"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="number"
android:id="@+id/sizeID"/>

</LinearLayout>

<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
/>

</LinearLayout>

</android.support.v7.widget.CardView>

</RelativeLayout>

最佳答案

尝试从您的 CardView

中删除 tools:targetApi="lollipop"

也用这个

android:foreground="?android:attr/selectableItemBackground"

代替这个

 android:foreground="?android:attr/selectableItemBackgroundBorderless

代码

<android.support.v7.widget.CardView
android:foreground="?android:attr/selectableItemBackground"
app:cardCornerRadius="10dp"
android:layout_width="match_parent"
android:layout_margin="@dimen/cardview_compat_inset_shadow"
android:layout_height="wrap_content"
>

关于android - 在使用 android 4.4 的 android 设备上将 CardView 膨胀到 Recyclerview 时发生 InflateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48577411/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com