gpt4 book ai didi

android - 使用 xml drawable 渲染问题

转载 作者:行者123 更新时间:2023-11-29 15:12:48 26 4
gpt4 key购买 nike

在 android studio 中,如果我将 .xml 可绘制对象设置为背景,我会遇到渲染问题,并且在运行应用程序时 - 看不到背景。

例如,我无法将此 xml 设置为布局的背景。

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/bad" />

如果我添加,例如,

android:tileMode="repeat"

结果是一样的。我还在背景附近看到红色感叹号:

enter image description here

这是堆栈跟踪:

java.lang.NullPointerException
at android.graphics.Bitmap_Delegate.createBitmap(Bitmap_Delegate.java:614)
at android.graphics.Bitmap_Delegate.createBitmap(Bitmap_Delegate.java:122)
at android.graphics.Bitmap_Delegate.createBitmap(Bitmap_Delegate.java:104)
at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:249)
at android.content.res.BridgeTypedArray.getDrawable(BridgeTypedArray.java:674)
at android.view.View.<init>(View.java:3730)
at android.view.ViewGroup.<init>(ViewGroup.java:491)
at android.widget.LinearLayout.<init>(LinearLayout.java:200)
at android.widget.LinearLayout.<init>(LinearLayout.java:196)
at android.widget.LinearLayout.<init>(LinearLayout.java:192)
at sun.reflect.GeneratedConstructorAccessor302.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at android.view.BridgeInflater.onCreateView(BridgeInflater.java:82)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:128)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:400)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:332)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:708)
at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:697)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:932)
at com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.java:697)
at com.android.tools.idea.rendering.RenderService.render(RenderService.java:816)
at com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel$6.run(AndroidDesignerEditorPanel.java:480)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
at com.intellij.util.Alarm$Request$1.run(Alarm.java:327)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

最佳答案

我喜欢这个解决方案。这非常简单。

我需要将 app_background 重命名为 app_background.xml

Android Studio 默认创建文件“app_background”,没有“.xml”扩展名。我以为 Android Studio 对我隐藏了 .xml,但是当我在资源管理器中打开文件夹时,我意识到文件的真实名称

关于android - 使用 xml drawable 渲染问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28740594/

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