Eclipse 图形布局:无法解析属性“背景”中的可绘制...
嗨。我正在向 Imageview 添加背景 xml 文件,但在 Eclipse 图形布局中收到此错误:
错误!无法解析可绘制对象 “com.android.ide.common.rendering.api.ResourceValue@1ae0c2” 在属性“背景”异常中 详细信息记录在“窗口”>“展示 查看>错误日志
当我在设备上运行小部件时,背景以正确的方式显示,但 Eclipse 中的错误确实很烦人。后台文件是:
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/grey_back_tile"
android:tileMode="repeat" />
这是我使用它的地方:
<ImageView android:layout_gravity="top|center_horizontal" android:layout_marginTop="4dp" android:layout_width="286dp" android:layout_height="47dp" android:background="@drawable/widget_background_banner"/>
错误日志堆栈跟踪显示:
org.xmlpull.v1.XmlPullParserException: 二进制 XML 文件第 5 行: 需要有效的 src 属性 android.graphics.drawable.BitmapDrawable.inflate(BitmapDrawable.java:341) 在 android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:779) 在 android.graphics.drawable.Drawable.createFromXml(Drawable.java:720) 在 com.android.layoutlib.bridge.ResourceHelper.getDrawable(ResourceHelper.java:150) 在 com.android.layoutlib.bridge.BridgeTypedArray.getDrawable(BridgeTypedArray.java:668) 在 android.view.View。(View.java:1846) 在 android.widget.ImageView。(ImageView.java:109) 在 android.widget.ImageView。(ImageView.java:105) 在 sun.reflect.GenerateConstructorAccessor16.newInstance(未知 来源)于 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(未知 来源)于 java.lang.reflect.Constructor.newInstance(未知 来源)于 android.view.LayoutInflater.createView(LayoutInflater.java:499) 在 android.view.BridgeInflater.onCreateView(BridgeInflater.java:77) 在 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562) 在 android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:122) 在 android.view.LayoutInflater.rInflate(LayoutInflater.java:617) 在 android.view.LayoutInflater.rInflate(LayoutInflater.java:620) 在 android.view.LayoutInflater.inflate(LayoutInflater.java:407) 在 android.view.LayoutInflater.inflate(LayoutInflater.java:296) 在 com.android.layoutlib.bridge.Bridge.computeLayout(Bridge.java:377) 在 com.android.ide.common.rendering.LayoutLibrary.createLegacySession(LayoutLibrary.java:394) 在 com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:276) 在 com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(未知 来源)位于 com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(未知 来源)于 com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(未知 来源)于 com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.activated(未知 来源)位于 com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.partActivated(未知 来源)位于 com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.partBroughtToTop(未知 来源)于 org.eclipse.ui.internal.PartListenerList$2.run(PartListenerList.java:87) 在 org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) 在 org.eclipse.core.runtime.Platform.run(Platform.java:888) 在 org.eclipse.ui.internal.PartListenerList.fireEvent(PartListenerList.java:57) 在 org.eclipse.ui.internal.PartListenerList.firePartBroughtToTop(PartListenerList.java:85) 在 org.eclipse.ui.internal.PartService.firePartBroughtToTop(PartService.java:208) 在 org.eclipse.ui.internal.WorkbenchPagePartList.firePartBroughtToTop(WorkbenchPagePartList.java:76) 在 org.eclipse.ui.internal.WorkbenchPagePartList.fireActiveEditorChanged(WorkbenchPagePartList.java:52) 在 org.eclipse.ui.internal.PartList.setActiveEditor(PartList.java:162) 在 org.eclipse.ui.internal.WorkbenchPage.makeActiveEditor(WorkbenchPage.java:1281) 在 org.eclipse.ui.internal.WorkbenchPage.setActivePart(WorkbenchPage.java:3530) 在 org.eclipse.ui.internal.WorkbenchPage.requestActivation(WorkbenchPage.java:3077) 在 org.eclipse.ui.internal.PartPane.requestActivation(PartPane.java:279) 在 org.eclipse.ui.internal.EditorPane.requestActivation(EditorPane.java:98) 在 org.eclipse.ui.internal.PartPane.setFocus(PartPane.java:325) 在 org.eclipse.ui.internal.EditorPane.setFocus(EditorPane.java:127) 在 org.eclipse.ui.internal.PartStack.presentationSelectionChanged(PartStack.java:844) 在 org.eclipse.ui.internal.PartStack.access$1(PartStack.java:827) 在 org.eclipse.ui.internal.PartStack$1.selectPart(PartStack.java:137) 在 org.eclipse.ui.internal.presentations.util.TabbedStackPresentation$1.handleEvent(TabbedStackPresentation.java:133) 在 org.eclipse.ui.internal.presentations.util.AbstractTabFolder.fireEvent(AbstractTabFolder.java:269) 在 org.eclipse.ui.internal.presentations.util.AbstractTabFolder.fireEvent(AbstractTabFolder.java:278) 在 org.eclipse.ui.internal.presentations.defaultpresentation.DefaultTabFolder.access$1(DefaultTabFolder.java:1) 在 org.eclipse.ui.internal.presentations.defaultpresentation.DefaultTabFolder$2.handleEvent(DefaultTabFolder.java:88) 在 org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) 在 org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053) 在 org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077) 在 org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062) 在 org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:774) 在 org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:2743) 在 org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1429) 在 org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:257) 在 org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) 在 org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053) 在 org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066) 在 org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657) 在 org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640) 在 org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604) 在 org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438) 在 org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671) 在 org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) 在 org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664) 在 org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) 在 org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115) 在 org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) 在 org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) 在 org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) 在 org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369) 在 org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native 方法)在 sun.reflect.NativeMethodAccessorImpl.invoke(未知 来源)于 sun.reflect.DelegatingMethodAccessorImpl.invoke(未知 来源)于 java.lang.reflect.Method.invoke(未知 来源)于 org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619) 在 org.eclipse.equinox.launcher.Main.basicRun(Main.java:574) 在 org.eclipse.equinox.launcher.Main.run(Main.java:1407)
当然,“grey_back_tile.png”是一个有效的资源,它位于“drawable-hdpi”文件夹中。有什么线索可以消除该错误吗?
Hi. I'm adding a background xml file to an Imageview but i get this error in the Eclipse Graphical layout:
error! Unable to resolve drawable
"com.android.ide.common.rendering.api.ResourceValue@1ae0c2"
in attribute "background" Exception
details are logged in Window > Show
View > Error Log
When i run the widget on the device, the background is displayed in the right way, but the error in Eclipse is really annoying. The background file is:
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/grey_back_tile"
android:tileMode="repeat" />
And here's where I use it:
<ImageView android:layout_gravity="top|center_horizontal" android:layout_marginTop="4dp" android:layout_width="286dp" android:layout_height="47dp" android:background="@drawable/widget_background_banner"/>
The error log stack trace shows:
org.xmlpull.v1.XmlPullParserException:
Binary XML file line #5:
requires a valid src attribute at
android.graphics.drawable.BitmapDrawable.inflate(BitmapDrawable.java:341)
at
android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:779)
at
android.graphics.drawable.Drawable.createFromXml(Drawable.java:720)
at
com.android.layoutlib.bridge.ResourceHelper.getDrawable(ResourceHelper.java:150)
at
com.android.layoutlib.bridge.BridgeTypedArray.getDrawable(BridgeTypedArray.java:668)
at
android.view.View.(View.java:1846)
at
android.widget.ImageView.(ImageView.java:109)
at
android.widget.ImageView.(ImageView.java:105)
at
sun.reflect.GeneratedConstructorAccessor16.newInstance(Unknown
Source) at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source) at
java.lang.reflect.Constructor.newInstance(Unknown
Source) at
android.view.LayoutInflater.createView(LayoutInflater.java:499)
at
android.view.BridgeInflater.onCreateView(BridgeInflater.java:77)
at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562)
at
android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:122)
at
android.view.LayoutInflater.rInflate(LayoutInflater.java:617)
at
android.view.LayoutInflater.rInflate(LayoutInflater.java:620)
at
android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at
android.view.LayoutInflater.inflate(LayoutInflater.java:296)
at
com.android.layoutlib.bridge.Bridge.computeLayout(Bridge.java:377)
at
com.android.ide.common.rendering.LayoutLibrary.createLegacySession(LayoutLibrary.java:394)
at
com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:276)
at
com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(Unknown
Source) at
com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(Unknown
Source) at
com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(Unknown
Source) at
com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.activated(Unknown
Source) at
com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.partActivated(Unknown
Source) at
com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.partBroughtToTop(Unknown
Source) at
org.eclipse.ui.internal.PartListenerList$2.run(PartListenerList.java:87)
at
org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at
org.eclipse.core.runtime.Platform.run(Platform.java:888)
at
org.eclipse.ui.internal.PartListenerList.fireEvent(PartListenerList.java:57)
at
org.eclipse.ui.internal.PartListenerList.firePartBroughtToTop(PartListenerList.java:85)
at
org.eclipse.ui.internal.PartService.firePartBroughtToTop(PartService.java:208)
at
org.eclipse.ui.internal.WorkbenchPagePartList.firePartBroughtToTop(WorkbenchPagePartList.java:76)
at
org.eclipse.ui.internal.WorkbenchPagePartList.fireActiveEditorChanged(WorkbenchPagePartList.java:52)
at
org.eclipse.ui.internal.PartList.setActiveEditor(PartList.java:162)
at
org.eclipse.ui.internal.WorkbenchPage.makeActiveEditor(WorkbenchPage.java:1281)
at
org.eclipse.ui.internal.WorkbenchPage.setActivePart(WorkbenchPage.java:3530)
at
org.eclipse.ui.internal.WorkbenchPage.requestActivation(WorkbenchPage.java:3077)
at
org.eclipse.ui.internal.PartPane.requestActivation(PartPane.java:279)
at
org.eclipse.ui.internal.EditorPane.requestActivation(EditorPane.java:98)
at
org.eclipse.ui.internal.PartPane.setFocus(PartPane.java:325)
at
org.eclipse.ui.internal.EditorPane.setFocus(EditorPane.java:127)
at
org.eclipse.ui.internal.PartStack.presentationSelectionChanged(PartStack.java:844)
at
org.eclipse.ui.internal.PartStack.access$1(PartStack.java:827)
at
org.eclipse.ui.internal.PartStack$1.selectPart(PartStack.java:137)
at
org.eclipse.ui.internal.presentations.util.TabbedStackPresentation$1.handleEvent(TabbedStackPresentation.java:133)
at
org.eclipse.ui.internal.presentations.util.AbstractTabFolder.fireEvent(AbstractTabFolder.java:269)
at
org.eclipse.ui.internal.presentations.util.AbstractTabFolder.fireEvent(AbstractTabFolder.java:278)
at
org.eclipse.ui.internal.presentations.defaultpresentation.DefaultTabFolder.access$1(DefaultTabFolder.java:1)
at
org.eclipse.ui.internal.presentations.defaultpresentation.DefaultTabFolder$2.handleEvent(DefaultTabFolder.java:88)
at
org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at
org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at
org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
at
org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
at
org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:774)
at
org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:2743)
at
org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1429)
at
org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:257)
at
org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at
org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at
org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
at
org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
at
org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
at
org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
at
org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
at
org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
at
org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at
org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown
Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source) at
java.lang.reflect.Method.invoke(Unknown
Source) at
org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
at
org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at
org.eclipse.equinox.launcher.Main.run(Main.java:1407)
Naturally the "grey_back_tile.png" is a valid resource, and it's located int the "drawable-hdpi" folder. Any clue to get rid of that error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道我迟到了,但面临着同样的问题。我很确定这是一个 Eclipse ADT 错误,但为了防止出现烦人的错误,如果您创建一个样式并向平铺背景添加背景项并将布局引用到该样式,而不是编辑布局上的背景属性,那么应该可以工作,并且您不会遇到烦人的错误。
因此,平铺背景 XML 命名为 app_background:
然后是一个样式,引用它:
然后将该样式分配给布局:
I know I am late to this but faced the same issue. I'm pretty certain it's an Eclipse ADT bug but to prevent the annoying errors, if you create a style and add a background item to your tiled background and refer the layout to that, as opposed to editing the background attribute on the layout, it should work and you won't get the annoying errors.
So, tiled background XML named app_background:
Then a style, referring to it:
And then assign the style to the layout: