Android - 抽屉导航 - ScrollView 无滚动

标签 android android-layout android-scrollview navigation-drawer

我有一个抽屉导航的问题。

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

我检查了我的 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);

谁能帮帮我?

最佳答案

尝试使用 NavigationDrawer instructions page 中的 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>

关于Android - 抽屉导航 - ScrollView 无滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18946369/

相关文章:

android - 使用 gradle buildTypes 的 android 的不同 Apks

android.database.sqlite.SQLiteCursor@435b9ba0

java - 如何将文本从一个 Activity 传递到另一个 Activity (android studio)

Android WebView跳到底部

android - ScrollView 上的 NumberPicker 在 Android 4.0.4 上不滚动

android - 如何动态创建一个按钮?

android - 如何使用此代码播放全屏视频?

android - 在 LinearLayout 中嵌套 TableLayout - 这可能吗?

java - 彩色图像按钮上的波纹效果?

java - ScrollView 不随 onTouch 滚动