在ADT布局编辑器中导航抽屉渲染错误

<FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" /> <ListView android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:background="#111" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" /> 

根据创build导航抽屉文档将其添加到布局xml中

 Exception raised during rendering: DrawerLayout must be measured with MeasureSpec.EXACTLY. Exception details are logged in Window > Show View > Error Log java.lang.IllegalArgumentException: DrawerLayout must be measured with MeasureSpec.EXACTLY. at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:591) at android.view.View.measure(View.java:15518) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825) at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) at android.view.View.measure(View.java:15518) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404) at android.widget.LinearLayout.measureVertical(LinearLayout.java:695) at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) at android.view.View.measure(View.java:15518) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404) at android.widget.LinearLayout.measureVertical(LinearLayout.java:695) at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) at android.view.View.measure(View.java:15518) at com.android.layoutlib.bridge.impl.RenderSessionImpl.measureView(RenderSessionImpl.java:607) at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:509) at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:334) at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:325) at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:440) at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1545) at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1302) at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.activated(GraphicalEditorPart.java:1059) at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.delegatePageChange(LayoutEditorDelegate.java:686) at com.android.ide.eclipse.adt.internal.editors.common.CommonXmlEditor.pageChange(CommonXmlEditor.java:360) at org.eclipse.ui.part.MultiPageEditorPart$2.widgetSelected(MultiPageEditorPart.java:292) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1276) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1300) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1285) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1079) at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:3028) at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1749) at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:278) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1276) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3562) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3186) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1053) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:942) at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86) at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124) 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:353) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584) at org.eclipse.equinox.launcher.Main.run(Main.java:1438) at org.eclipse.equinox.launcher.Main.main(Main.java:1414) 

Solutions Collecting From Web of "在ADT布局编辑器中导航抽屉渲染错误"

我有类似的问题。 如果您想要预览布局,您可以暂时将宽度和高度更改为绝对值。

例如:-

 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="400px" android:layout_height="800px"> 

这在7月份发布的支持库的第18版中得到了修复。

在Eclipse中右键单击你的项目>selectandroid tools>添加支持库。

固定。 🙂

从另一个问题我通过扩展DrawerLayout解决了问题,并强制正确的Measure_Specs:

 public class CustomDrawerLayout extends DrawerLayout { public CustomDrawerLayout(Context context) { super(context); } public CustomDrawerLayout(Context context, AttributeSet attrs) { super(context, attrs); } public CustomDrawerLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { widthMeasureSpec = MeasureSpec.makeMeasureSpec( MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY); heightMeasureSpec = MeasureSpec.makeMeasureSpec( MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.EXACTLY); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } 

Asmok的回答很好,但是我总是忘记这种“临时性”编辑。 (换句话说,临时可能会变得非常大^^)

因此,我使用<include>标签并将布局分成两个文件。

 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- The main content view --> <include layout="@layout/main_layout" /> <!-- The navigation drawer --> <include layout="@layout/navigation_drawer"/> </android.support.v4.widget.DrawerLayout> 

对于主布局(这是所讨论的活动的UI),我现在可以使用Eclipse的graphics编辑器,因为所有内容都位于单个文件main_layout.xml
此外,我可以轻松地将导航抽屉包含在不同的活动中,而无需复制和粘贴代码。

我find的最简单的解决scheme是预览Theme.Holo.Light.Dialog.FixedSizefunction和和平…

图片在这里

自定义视图难以正确显示在eclipse中的UI编辑器(同样适用于Android Studio中的UI编辑器)。 这个是正常的。