我有一个自定义视图,其中包含以下视图层次结构:
[LinearLayout]
[CardView]
[LinearLayout]
[RecyclerView]
最后RecyclerView
的每个项目都包含 3个矢量绘图。当我在KitKat(api 19)上运行应用程序时,StackOverflowError
发生了
FATAL EXCEPTION: main
Process: com.tsse.spain.myvodafone, PID: 3405
java.lang.StackOverflowError
at android.graphics.Matrix.mapVectors(Matrix.java:684)
at android.support.graphics.drawable.VectorDrawableCompat$VPathRenderer.getMatrixScale(VectorDrawableCompat.java:1300)
at android.support.graphics.drawable.VectorDrawableCompat$VPathRenderer.drawPath(VectorDrawableCompat.java:1207)
at android.support.graphics.drawable.VectorDrawableCompat$VPathRenderer.drawGroupTree(VectorDrawableCompat.java:1184)
at android.support.graphics.drawable.VectorDrawableCompat$VPathRenderer.draw(VectorDrawableCompat.java:1193)
at android.support.graphics.drawable.VectorDrawableCompat$VectorDrawableCompatState.updateCachedBitmap(VectorDrawableCompat.java:1023)
at android.support.graphics.drawable.VectorDrawableCompat.draw(VectorDrawableCompat.java:366)
at android.view.View.draw(View.java:14450)
at android.view.View.getDisplayList(View.java:13362)
at android.view.View.getDisplayList(View.java:13404)
at android.view.View.draw(View.java:14182)
at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
at android.view.View.draw(View.java:14468)
at android.view.View.getDisplayList(View.java:13362)
at android.view.View.getDisplayList(View.java:13404)
at android.view.View.draw(View.java:14182)
at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
at android.view.View.getDisplayList(View.java:13357)
at android.view.View.getDisplayList(View.java:13404)
at android.view.View.draw(View.java:14182)
at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
at android.view.View.getDisplayList(View.java:13357)
at android.view.View.getDisplayList(View.java:13404)
at android.view.View.draw(View.java:14182)
at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
at android.support.v7.widget.RecyclerView.drawChild(RecyclerView.java:4477)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
at android.view.View.draw(View.java:14468)
at android.support.v7.widget.RecyclerView.draw(RecyclerView.java:3869)
at android.view.View.getDisplayList(View.java:13362)
at android.view.View.getDisplayList(View.java:13404)
at android.view.View.draw(View.java:14182)
at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
at android.view.View.getDisplayList(View.java:13357)
at android.view.View.getDisplayList(View.java:13404)
at android.view.View.draw(View.java:14182)
at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
at android.view.View.draw(View.java:14468)
at android.widget.FrameLayout.draw(FrameLayout.java:472)
at android.view.View.getDisplayList(View.java:13362)
at android.view.View.getDisplayList(View.java:13404)
at android.view.View.draw(View.java:14182)
at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
at android.view.View.draw(View.java:14468)
at android.view.View.getDisplayList(View.java:13362)
at android.view.View.getDisplayList(View.java:13404)
at android.view.View.draw(View.java:14182)
at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
at android.view.View.getDisplayList(View.java:13357)
at android.view.View.getDisplayList(View.java:13404)
at android.view.View.draw(View.java:14182)
at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
at android.view.View.getDisplayList(View.java:13357)
at android.view.View.getDisplayList(View.java:13404)
at android.view.View.draw(View.java:14182)
at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
at android.support.v7.widget.RecyclerView.drawChild(RecyclerView.java:4477)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940
我在AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
Application
onCreate()
和vectorDrawables.useSupportLibrary = true
build.gradle
中http://localhost:3000
启用200
的矢量绘图
当我使用普通的 PNG drawable时,错误不会发生。
我做错了什么?
答案 0 :(得分:0)
在onBindViewHolder
中以编程方式创建 vector-drawable 并将其设置为您的视图: -
Drawable your_vector_drawable = VectorDrawableCompat.create(context.getResources(), R.drawable.vectorDrawable, null);
现在将此drawable设置为onBindViewHolder
...
yourView.setBackground(your_vector_drawable);
这有望解决:)
这是一个较低的api问题......
答案 1 :(得分:0)
我首先将矢量drawable转换为Bitmap
,然后使用ImageView.setImageBitmap(Bitmap)
将其提供给ImageView,从而解决了这个问题。这样做效率较低,但完成工作