DrawerLayout不是滑动抽屉

时间:2015-02-06 06:54:08

标签: android xml android-support-library

我查看了这个问题的所有其他答案,但仍然无法解决此错误:

app:id/drawerLayout) is not a sliding drawer

我在closeDrawer行上遇到错误:

    mDrawerLinear = (LinearLayout) findViewById(R.id.drawerLayout);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.drawer_list);

    mDrawerLayout.closeDrawer(mDrawerLinear);

我正在设置内容这个xml>

<RelativeLayout 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.support.v4.widget.DrawerLayout 
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <!-- The main content view -->
    <include layout="@layout/mainv2"/>

    <!-- The navigation drawer -->
    <include layout="@layout/navigation_drawer"/>

    </android.support.v4.widget.DrawerLayout>

</RelativeLayout>

和navigation_drawer xml看起来像这样

<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawerLayout"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:background="@android:color/black"
        android:gravity="left"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

        <TextView
        android:id="@+id/fbName"
        android:layout_width="240dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="10dp"
        android:text="Please login."
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="@android:color/white"
        android:textSize="12dp" />


        </LinearLayout>

        <ListView
        android:id="@+id/drawer_list"
        android:layout_width="240dp"
        android:layout_height="match_parent"

        android:background="#111"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp" />

  </LinearLayout>

我必须遗漏一些明显的东西。有什么想法吗?

1 个答案:

答案 0 :(得分:3)

抽屉LinearLayout的重力属性错误。 android:gravity="left"属性应为android:layout_gravity="left"