gpt4 book ai didi

android - 渐变在 Android M 上因 IllegalArgumentException 而崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:02:11 27 4
gpt4 key购买 nike

在我的应用程序中,我使用渐变背景。我曾经用我的手机在 Lollipop 上调试它,一切正常。今天我将我的手机 (LG G4) 更新为棉花糖,现在当应该绘制渐变时,应用程序崩溃并显示以下堆栈跟踪:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.max.lucas, PID: 28163
java.lang.IllegalArgumentException: color and position arrays must be of equal length
at android.graphics.LinearGradient.<init>(LinearGradient.java:58)
at android.graphics.drawable.GradientDrawable.ensureValidRect(GradientDrawable.java:942)
at android.graphics.drawable.GradientDrawable.draw(GradientDrawable.java:516)
at android.view.View.getDrawableRenderNode(View.java:16451)
at android.view.View.drawBackground(View.java:16387)
at android.view.View.draw(View.java:16197)
at android.view.View.updateDisplayListIfDirty(View.java:15202)
at android.view.View.draw(View.java:15976)
at android.view.ViewGroup.drawChild(ViewGroup.java:3611)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3401)
at android.view.View.updateDisplayListIfDirty(View.java:15197)
at android.view.View.draw(View.java:15976)
at android.view.ViewGroup.drawChild(ViewGroup.java:3611)
at android.support.v7.widget.RecyclerView.drawChild(RecyclerView.java:3588)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3401)
at android.view.View.draw(View.java:16209)
at android.support.v7.widget.RecyclerView.draw(RecyclerView.java:3097)
at android.view.View.updateDisplayListIfDirty(View.java:15202)
at android.view.View.draw(View.java:15976)
at android.view.ViewGroup.drawChild(ViewGroup.java:3611)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3401)
at android.view.View.draw(View.java:16209)
at android.support.design.internal.ScrimInsetsFrameLayout.draw(ScrimInsetsFrameLayout.java:82)
at android.view.View.updateDisplayListIfDirty(View.java:15202)
at android.view.View.draw(View.java:15976)
at android.view.ViewGroup.drawChild(ViewGroup.java:3611)
at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:1229)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3401)
at android.view.View.draw(View.java:16209)
at android.view.View.updateDisplayListIfDirty(View.java:15202)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3595)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3575)
at android.view.View.updateDisplayListIfDirty(View.java:15162)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3595)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3575)
at android.view.View.updateDisplayListIfDirty(View.java:15162)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3595)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3575)
at android.view.View.updateDisplayListIfDirty(View.java:15162)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3595)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3575)
at android.view.View.updateDisplayListIfDirty(View.java:15162)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3595)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3575)
at android.view.View.updateDisplayListIfDirty(View.java:15162)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:281)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:287)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:322)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2655)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2469)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2098)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1125)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6100)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main

我注意到崩溃仅发生在渐变的属性引用 AppTheme 值时,如下所示:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:startColor="?attr/colorPrimary"
android:centerColor="#000066"
android:endColor="?attr/colorPrimary"
android:type="linear"
android:angle="135"/>
</shape>

具有固定值的渐变效果很好:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:startColor="#3F51B5"
android:centerColor="#4CAF50"
android:endColor="#3F51B5"
android:type="linear"
android:angle="135"/>
</shape>

是什么原因导致的,我该如何解决?

最佳答案

一个可能迟到的答案,但可能对 future 的开发者有所帮助。对于那些类型的渐变文件,总是力求使用相同的颜色格式。例如,如果您使用的是十六进制值,请使用 in all

<gradient
android:startColor="#3F51B5"
android:centerColor="#4CAF50"
android:endColor="#3F51B5"/>

你们中的一些人正在引用主题颜色,

<gradient
android:startColor="?attr/colorPrimary"
android:centerColor="?attr/colorAccent"
android:endColor="?attr/colorPrimary"/>

关于android - 渐变在 Android M 上因 IllegalArgumentException 而崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35363335/

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