导航抽屉 - 右抽屉不会打开

时间:2014-12-10 19:20:12

标签: java android navigation-drawer drawerlayout

我在DrawerLayout上有2个抽屉时遇到问题。我的布局中有2 ListView,但只打开了正确的layout_gravity=start/left <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="600dp" android:layout_height="800dp"> <!-- The main content view --> <LinearLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <com.lablabla.homedestroyer.GameView android:id="@+id/gameView" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> <!-- Listview to display slider menu --> <ListView android:id="@+id/left_drawer" android:layout_width="180dp" android:layout_height="match_parent" android:layout_gravity="start" android:background="#111" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" /> <!-- Right Drawer - Weapons --> <ListView android:id="@+id/right_drawer" android:layout_width="180dp" android:layout_height="match_parent" android:layout_gravity="end" android:background="#111" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" /> </android.support.v4.widget.DrawerLayout> 。我设置的重力并不重要。

为了让2人一起工作,是否需要设置一些特殊的东西?也许在清单?

activity_main.xml中

Activity

并在mPlanetTitles = getResources().getStringArray(R.array.planets_array); mWeaponsTiltes = getResources().getStringArray(R.array.weapons_array); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mMenuDrawerList = (ListView) findViewById(R.id.left_drawer); // Set the adapter for the list view mMenuDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles)); // Set the list's click listener mMenuDrawerList.setOnItemClickListener(new MenuDrawerItemClickListener()); mWeaponsDrawerList = (ListView) findViewById(R.id.right_drawer); // Set the adapter for the list view mWeaponsDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mWeaponsTiltes)); mWeaponsDrawerList.setOnItemClickListener(new WeaponsDrawerItemClickListener()); // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(menuDrawerListener);

中引用它们

MainActivity.java -

findViewById

两个ListView调用DrawerListener的工作并返回非空值

修改 private DrawerListener menuDrawerListener = new DrawerListener() { @Override public void onDrawerStateChanged(int arg0) { Log.d("DrawerListener", "Changed"); } @Override public void onDrawerSlide(View arg0, float arg1) { Log.d("DrawerListener", "Slided"); } @Override public void onDrawerOpened(View arg0) { Log.d("DrawerListener", "Opened"); } @Override public void onDrawerClosed(View arg0) { Log.d("DrawerListener", "Closed"); } };

的代码
{{1}}

0 个答案:

没有答案