为什么这个抽屉强制关闭我的应用程序?
Why this Drawer Force Closes my app?
我没有更改我的应用程序的这一部分,但是在我重建它之后,这个强制关闭显示:
java.lang.IllegalStateException: Child drawer has absolute gravity LEFT but this DrawerLayout already has a drawer view along that edge Exception.
我的Activity布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/draw"
xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lin_hime_body"
android:orientation="vertical">
<include
layout="@layout/lay_title_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frm_home"/>
</LinearLayout>
<LinearLayout
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical"
android:id="@+id/menu1">
<include layout="@layout/lay_menu1"/>
</LinearLayout>
<LinearLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical"
android:id="@+id/menu2">
<include layout="@layout/lay_menu2"/>
</LinearLayout>
<LinearLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:orientation="vertical"
android:id="@+id/menu3">
<include layout="@layout/lay_menu3"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
我遇到了这个异常
java.lang.IllegalStateException: Child drawer has absolute gravity
LEFT but this DrawerLayout already has a drawer view along that edge
at
android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1089)
at android.view.View.measure(View.java:18916)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5972)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18916)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5972)
at
android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18916)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5972)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at
com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2693)
at android.view.View.measure(View.java:18916)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2218)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1294)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1536)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1185)
at
android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6255)
at
android.view.Choreographer$CallbackRecord.run(Choreographer.java:873)
at android.view.Choreographer.doCallbacks(Choreographer.java:676)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:859)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5885)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:819)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:709)
如果有效,试试这个:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/draw"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/lin_hime_body"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="@layout/lay_title_main"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/frm_home"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="@+id/menu1"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical">
<include layout="@layout/lay_menu1" />
</LinearLayout>
<LinearLayout
android:id="@+id/menu2"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical">
<include layout="@layout/lay_menu2" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/menu3"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:orientation="vertical">
<include layout="@layout/lay_menu3" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
你的 DrawerLayout 应该恰好有 2 个 children 并且它应该有 gravity 属性来描述你希望抽屉从哪里打开
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/your_actiivity_views_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>
我没有更改我的应用程序的这一部分,但是在我重建它之后,这个强制关闭显示:
java.lang.IllegalStateException: Child drawer has absolute gravity LEFT but this DrawerLayout already has a drawer view along that edge Exception.
我的Activity布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/draw"
xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lin_hime_body"
android:orientation="vertical">
<include
layout="@layout/lay_title_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frm_home"/>
</LinearLayout>
<LinearLayout
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical"
android:id="@+id/menu1">
<include layout="@layout/lay_menu1"/>
</LinearLayout>
<LinearLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical"
android:id="@+id/menu2">
<include layout="@layout/lay_menu2"/>
</LinearLayout>
<LinearLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:orientation="vertical"
android:id="@+id/menu3">
<include layout="@layout/lay_menu3"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
我遇到了这个异常
java.lang.IllegalStateException: Child drawer has absolute gravity
LEFT but this DrawerLayout already has a drawer view along that edge
at
android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1089)
at android.view.View.measure(View.java:18916)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5972)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18916)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5972)
at
android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18916)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5972)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at
com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2693)
at android.view.View.measure(View.java:18916)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2218)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1294)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1536)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1185)
at
android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6255)
at
android.view.Choreographer$CallbackRecord.run(Choreographer.java:873)
at android.view.Choreographer.doCallbacks(Choreographer.java:676)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:859)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5885)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:819)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:709)
如果有效,试试这个:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/draw"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/lin_hime_body"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="@layout/lay_title_main"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/frm_home"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="@+id/menu1"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical">
<include layout="@layout/lay_menu1" />
</LinearLayout>
<LinearLayout
android:id="@+id/menu2"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical">
<include layout="@layout/lay_menu2" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/menu3"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:orientation="vertical">
<include layout="@layout/lay_menu3" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
你的 DrawerLayout 应该恰好有 2 个 children 并且它应该有 gravity 属性来描述你希望抽屉从哪里打开
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/your_actiivity_views_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>