我正在使用此处的解决方案为我的应用程序制作渐变背景初始屏幕: 如何获得安卓渐变中心光效果?
我正在使用Vadym发布的解决方案:
<item >
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="@android:color/transparent"
android:endColor="@android:color/black"
android:centerX="50%"
android:centerY="50%"
android:gradientRadius="100%"
android:type="radial"/>
</shape>
</item>
不幸的是,这导致整个手机仅在Android 5.0上重新启动启动!不是 5.1 或 4.4 或 6.0 或 7.0 那里发生了什么?我什至无法评论 Vadyms 解决方案,因为我仍然没有足够的声誉。有人可以在评论中添加警告吗?
洛格猫 说:
08-10 09:50:57.395 22267-22292/system_process E/AndroidRuntime: *** FATAL EXCEPTION IN SYSTEM PROCESS: android.display
java.lang.IllegalArgumentException: radius must be > 0
at android.graphics.RadialGradient.<init>(RadialGradient.java:57)
at android.graphics.drawable.GradientDrawable.ensureValidRect(GradientDrawable.java:938)
at android.graphics.drawable.GradientDrawable.draw(GradientDrawable.java:509)
at android.graphics.drawable.LayerDrawable.draw(LayerDrawable.java:537)
at android.view.View.drawBackground(View.java:15352)
at android.view.View.draw(View.java:15105)
at android.widget.FrameLayout.draw(FrameLayout.java:592)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2606)
at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2613)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2526)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2337)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1968)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5786)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
at com.android.server.ServiceThread.run(ServiceThread.java:46)
在 API<21 上,gradientRadius
不接受 % 值。要解决此问题,您可以使用%p
(https://developer.android.com/reference/android/graphics/drawable/GradientDrawable.html#attr_android:gradientRadius(
android:gradientRadius="100%p"
试试这个;
System.runFinalization();
Runtime.getRuntime().gc();
System.gc();