1

我的导航抽屉有问题。

我无法在导航抽屉内滚动......但我的列表视图中有足够的项目。

我检查了我的 xml,但没有找到导致问题的任何原因。

这是我定义 ListView 的“主要”XML:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com   /apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Hauptmenue_extended" >

<ListView
    android:id="@+id/left_drawer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="start"
    android:background="#fff" />


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

这是我的代码:

mDrawerLayout = (DrawerLayout) findViewById(R.id.fragView);
        mDrawerList = (ListView) findViewById(R.id.left_drawer);
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
                GravityCompat.START);

        // Get the titles ... 
        drawerTitles = getResources().getStringArray(
                R.array.drawerTitles_array);
        // Get the sub titles ...
        drawerSubtitles = getResources().getStringArray(
                R.array.drawerSubtitles_array);
        // Set the icons ... 
        drawerIcons = new int[] { R.drawable.icon_buergermeldung,
                R.drawable.icon_sprechblase,
                R.drawable.icon_action_settings_dark, R.drawable.icon_user_chat, R.drawable.icon_haus, R.drawable.icon_contact, R.drawable.icon_calendar, R.drawable.icon_search, R.drawable.icon_zaehlerstand };

        // Create new MenuListAdapter
        MenuListAdapter mMenuAdapter = new MenuListAdapter(this,
                drawerTitles, drawerSubtitles, drawerIcons);

        mDrawerList.setAdapter(mMenuAdapter);
        mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

        // Add Navigation Drawer to Action Bar 
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                R.drawable.ic_drawer, R.string.drawer_open,
                R.string.drawer_close) {
            public void onDrawerClosed(View view) {
                getSupportActionBar().setTitle(mTitle);
                supportInvalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {
                getSupportActionBar().setTitle(R.string.app_name);
                supportInvalidateOptionsMenu();
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);

谁能帮我?

4

1 回答 1

3

尝试使用NavigationDrawer 说明页面中的 XML 代码。一些差异对我来说很突出。例如,将 ListView 高度设置为 match_parent 而不是 wrap_content(我知道这很奇怪),并确保包含内容的 FrameLayout。

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <!-- The navigation drawer -->
    <ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
于 2013-09-22T18:38:27.167 回答