ScrollView作为导航抽屉中的第一个元素

时间:2015-07-22 08:59:48

标签: android android-layout navigation-drawer

我试图创建一个看起来像Google Play商店的导航抽屉。我在谷歌游戏商店抽屉里注意到的是它可以从上到下滚动(不仅仅是列表视图)。我设法创造了一个可以正确打开和关闭的漂亮抽屉。但是当我使用scrollview作为抽屉布局中的第一个元素时,导航抽屉故障并且总是在屏幕上显示为分散的布局。 我使用这段代码(为了清晰起见,我删除了scrollview内容,另外,即使只有一个带有2-3个简单按钮的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">
    <!-- Main Layout -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
        android:orientation="vertical"
        android:id="@+id/screen"
        android:layout_height="wrap_content"
        tools:context=".Intro"
        android:weightSum="1">
    </LinearLayout>
    <!-- Drawer Layout -->
    <ScrollView
        android:layout_width="270dp"
        android:layout_height="match_parent">

....
....
...
    </ScrollView>

请注意,我在滚动视图中使用了固定高度元素,并且还删除了所有列表视图&amp;没有任何运气的可扩展列表视图(具有自动滚动的视图)。

1 个答案:

答案 0 :(得分:0)

我使用导航抽屉如下:

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

    <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    <fragment android:id="@+id/navigation_drawer"
              android:layout_width="@dimen/navigation_drawer_width"
              android:layout_height="match_parent"
              android:layout_gravity="left"
              android:name="com.xxx.NavigationDrawerFragment"
              tools:layout="@layout/fragment_navigation_drawer"/>

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

在片段布局中

<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:background="@color/white"
              tools:context=".com.xxx.NavigationDrawerFragment">

    <ScrollView
            android:id="@+id/list_drawer_menu"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

</LinearLayout>