DrawerLayout没有滚动,固定高度

时间:2015-03-12 10:00:17

标签: android scroll drawerlayout

在我的应用程序中,我使用DrawerLayout进行横向菜单。在这个菜单中,我有一个标题,ListView中的6行和图像页脚。这是我的横向菜单,我希望它有一个固定的高度(fill_parent),因为它永远不会改变,我不想在这个菜单中滚动,我该怎么办?

这是我的DrawerLayout:

<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"
        android:background="@color/backgr_greysoft" />

    <!-- The navigation drawer -->
    <ListView android:id="@+id/lista"
        android:layout_width="@dimen/listDrawer_width"
        android:layout_height="fill_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@color/backgr_greysoft"
        android:dividerHeight="1dp"
        android:background="@color/navdrw_grey" />
</android.support.v4.widget.DrawerLayout>

我希望所有智能手机具有相同的功能,我不希望在某些情况下滚动,而不是在智能手机更大的其他情况下滚动。

编辑:

  

// DRAWERLAYOUT

    navDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    //Lista
    navList = (ListView) findViewById(R.id.lista);
    //Declaramos el header de Navigation Drawer
    View header = getLayoutInflater().inflate(R.layout.search, null);
    //Establecemos el header
    navList.addHeaderView(header);
    //Declaramos el pie de Navigation Drawer
    View footer = getLayoutInflater().inflate(R.layout.navfooter, null);
    //Establecemos el pie
    navList.addFooterView(footer);
    //Tomamos listado de imágenes desde drawable
    navIcons = getResources().obtainTypedArray(R.array.navigation_iconos);
    //Tomamos listado de títulos desde el string-array de los recursos
    titulos = getResources().getStringArray(R.array.nav_options);
    //Listado de títulos de barra de navegación
    navItems = new ArrayList<Navigation_Item>();
    //Agregamos objetos Navigation_Item al array
    //ESCANER
    navItems.add(new Navigation_Item(titulos[0], navIcons.getResourceId(0, -1)));
    //DESCARGAS
    navItems.add(new Navigation_Item(titulos[1], navIcons.getResourceId(1, -1)));
    //FOTOGRAFÍAS
    navItems.add(new Navigation_Item(titulos[2], navIcons.getResourceId(2, -1)));
    //FAVORITOS
    navItems.add(new Navigation_Item(titulos[3], navIcons.getResourceId(3, -1)));
    //CONFIGURACIÓN
    navItems.add(new Navigation_Item(titulos[4], navIcons.getResourceId(4, -1)));
    //COMPARTIR APLICACIÓN
    navItems.add(new Navigation_Item(titulos[5], navIcons.getResourceId(5, -1)));
    //Declaramos y seteamos el adaptador al cual le pasamos el array con los títulos
    navAdapter = new NavigationAdapter(this, navItems);
    navList.setAdapter(navAdapter);

非常感谢。

1 个答案:

答案 0 :(得分:0)

使用垂直LinearLayout代替ListView。列表具有隐式滚动,因为它们可能显示多个项目。

<LinearLayout>
    <Button1>
    <Button2>
    ...
</LinearLayout>

编辑:

尝试此布局(方便地调整代码):

<?xml version="1.0" encoding="utf-8"?>
<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"
        android:background="@color/backgr_greysoft" />

    <!-- The navigation drawer -->
    <LinearLayout
        android:id="@+id/left_drawer"
        android:layout_width="290dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/background_light"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/lista"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="start"
            android:layout_weight="1"
            android:background="@color/navdrw_grey"
            android:choiceMode="singleChoice"
            android:divider="@color/backgr_greysoft"
            android:dividerHeight="1dp" />

        <!-- FOOTER: ADD THE REST OF FOOTER ITEMS INSIDE IT (or replace container by a view if you only need that view as footer: a TextView for instance) -->
        <LinearLayout
            android:id="@+id/drawer_footer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Footer" />
        </LinearLayout>
    </LinearLayout>
</android.support.v4.widget.DrawerLayout>