当我只有1时双抽屉错误

时间:2016-05-27 08:08:09

标签: android xml android-layout drawer

我试图在我的激动项目中添加NavigationDrawer,当我运行应用程序并在android studio的设计窗口中时,会出现此错误:

java.lang.IllegalStateException: Child drawer has absolute gravity LEFT but this DrawerLayout already has a drawer view along that edge

我自己试图解决它,但无法找到错误所在的第二个抽屉,为什么我会收到错误?这是xml fileI

<?xml version="1.0" encoding="utf-8"?>
<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/app_bar_main"
        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:fitsSystemWindows="true"
        app:headerLayout="@layout/drawer_header_main"
        app:menu="@menu/drawermenu" />

    <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" />

    <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:weightSum="1"
        tools:context=".MainActivity">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="34dp">

            <TextView
                android:id="@+id/labelGold"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:text="@string/labelGold"
                android:textSize="20dp" />

            <TextView
                android:id="@+id/textViewGold"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginStart="10dp"
                android:layout_toEndOf="@+id/labelGold"
                android:text="0"
                android:textSize="20dp" />
        </RelativeLayout>

        <LinearLayout
            android:id="@+id/fragmentParentViewGroup"
            android:layout_width="match_parent"
            android:layout_height="437dp"
            android:orientation="vertical">

            <fragment
                android:id="@+id/avatarFragment"
                android:name="com.owlfinity.zeepblok.taskjournal.AvatarFragment"
                android:layout_width="match_parent"
                android:layout_height="181dp"
                tools:layout="@layout/avatarfragment" />

            <fragment
                android:id="@+id/taskListFragment"
                android:name="com.owlfinity.zeepblok.taskjournal.TaskListFragment"
                android:layout_width="match_parent"
                android:layout_height="166dp"
                android:layout_weight="0.35"
                tools:layout="@layout/tasklistlayout" />
        </LinearLayout>

        <Button
            android:id="@+id/buttonNew"
            android:layout_width="128dp"
            android:layout_height="48dp"
            android:layout_gravity="center_horizontal"
            android:background="@drawable/button"
            android:onClick="newTask"
            android:text="@string/button_new" />
    </LinearLayout>
</android.support.v4.widget.DrawerLayout>

编辑1 ============================================= =========

以下是MainActivity的OnCreate

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);

    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);


    dbHelper = new DBHelper(this);
    textViewGold = (TextView) findViewById(R.id.textViewGold);
    taskListFragment = (TaskListFragment) getSupportFragmentManager().findFragmentByTag("taskList");
    inventoryFragment = (InventoryFragment) getSupportFragmentManager().findFragmentByTag("inventory");
    loadGuiStuff();

    if (taskListFragment == null)
    {
        taskListFragment = new TaskListFragment();
        transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.fragmentParentViewGroup, taskListFragment);
        transaction.commit();
    }


}

1 个答案:

答案 0 :(得分:0)

修正了它,需要清理项目......