DrawerLayout must be measured with MeasureSpec.EXACTLY error

前端 未结 12 2389
独厮守ぢ
独厮守ぢ 2020-12-03 16:54

I am trying to implement a Navigation drawer, but I keep getting this error. I saw the similar questions but did not work for me. I have the following layout activity_main2.

相关标签:
12条回答
  • 2020-12-03 17:14

    Got to Build->Clean project then Rebuild project error will be solve

    0 讨论(0)
  • 2020-12-03 17:16

    My DrawerLayout was inside a LinearLayout:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@drawable/abohawawallpapersqr"
        tools:context=".MainActivity">
    
            <include layout="@layout/toolbar" />
    
            <android.support.v4.widget.DrawerLayout
                android:id="@+id/drawerLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"> 
    
            <!-- ...... -->
            </android.support.v4.widget.DrawerLayout>
    </LinearLayout>
    

    Then I solved the problem by changing the layout_height="wrap_content" to layout_height="match_parent" of LinearLayout.So the code is:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@drawable/abohawawallpapersqr"
        tools:context=".MainActivity">
    
    0 讨论(0)
  • 2020-12-03 17:18
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    

    was solved my problem by creating the activity like below;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainmenu);
    }
    
    0 讨论(0)
  • 2020-12-03 17:19

    use this ...

    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);
        }
    }
    
    0 讨论(0)
  • 2020-12-03 17:21

    This can also happen because of the new ConstraintLayout. Make sure the drawer layout isn't in the hierarchy of ConstraintLayout.

    0 讨论(0)
  • 2020-12-03 17:21

    If you still get this Exception make sure that your activity is full Screen defined In Manifest u can do in Activity:

    android:theme="@style/Theme.AppCompat.Light.FullScreen"
    

    Or define this in styles.xml:

     <style name="Theme.AppCompat.Light.FullScreen" parent="@style/Theme.AppCompat.Light.NoActionBar">
            <item name="android:windowNoTitle">false</item>
            <item name="android:windowActionBar">true</item>
            <item name="android:windowFullscreen">true</item>
            <item name="android:windowContentOverlay">@null</item>
        </style>
    
    0 讨论(0)
提交回复
热议问题