导航抽屉中的滚动视图

ScrollView in Navigation Drawer

我设计了自己的自定义导航抽屉,它看起来像这样:

此导航抽屉的 xml 代码是:

<RelativeLayout
    android:id="@+id/UserOptionsDrawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@color/nav_drawer_background_black"
    tools:layout="@layout/fragment_navigation_drawer">

    <!-- Cover or Banner -->

    <RelativeLayout
        android:id="@+id/rlBanner"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:orientation="vertical">

        <!-- Cover Pic Container -->
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="150dp">

            <!-- Cover Picture -->
            <ImageView
                android:id="@+id/ivCoverPic"
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:scaleType="centerCrop"
                android:src="@drawable/cover_pic"/>

            <!-- Tint -->
            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:id="@+id/llCoverTint">
            </LinearLayout>
        </RelativeLayout>

        <!-- Profile Pic Container -->
        <LinearLayout
            android:id="@+id/llProfilePicContainer"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="7dp"
            android:orientation="vertical">

            <com.example.neotavraham.MLRoundedImageView
                android:id="@+id/civProfilePic"
                android:src="@drawable/ic_no_user"
                android:layout_height="65dp"
                android:layout_width="65dp"
                />

        </LinearLayout>

        <TextView
            android:id="@+id/tvUserName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/llProfilePicContainer"
            android:layout_marginTop="10dp"
            android:layout_toRightOf="@+id/llProfilePicContainer"
            android:textColor="#ffffff"
            android:textSize="15sp"
            android:text="Username"/>

        <TextView
            android:id="@+id/tvUserEmail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/tvUserName"
            android:layout_below="@+id/tvUserName"
            android:textColor="#ffffff"
            android:textSize="12sp"
            android:text="example@hostname.com"/>

    </RelativeLayout>

    <TextView
        android:id="@+id/tvShabatCategory"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:gravity="right"
        android:layout_marginRight="5dp"
        android:layout_below="@id/rlBanner"
        android:text="עדכון זמני שבת"
        android:textSize="15dp"
        android:textColor="@android:color/white"
        android:textAppearance="?android:attr/textAppearanceSmall"/>

    <!-- ListMenu -->

    <ListView
        android:id="@+id/navigation_menu_container"
        android:layout_width="240dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/tvShabatCategory"
        android:layout_gravity="start"
        android:background="@android:color/transparent"
        android:choiceMode="singleChoice"
        android:divider="@color/divider_orange"
        android:dividerHeight="2dp" >
    </ListView>

    <TextView
        android:id="@+id/tvWeeklyCategory"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:gravity="right"
        android:layout_marginRight="5dp"
        android:layout_below="@id/navigation_menu_container"
        android:text="עדכון זמני השבוע"
        android:textSize="15dp"
        android:textColor="@android:color/white"
        android:textAppearance="?android:attr/textAppearanceSmall"/>

    <ListView
        android:id="@+id/lv_weekly_updates"
        android:layout_width="240dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/tvWeeklyCategory"
        android:layout_gravity="start"
        android:background="@android:color/transparent"
        android:choiceMode="singleChoice"
        android:divider="@color/divider_orange"
        android:dividerHeight="2dp" >
    </ListView>

    <TextView
        android:id="@+id/tvMessagesCategory"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:gravity="right"
        android:layout_marginRight="5dp"
        android:layout_below="@id/lv_weekly_updates"
        android:text="עדכון הודעות"
        android:textSize="15dp"
        android:textColor="@android:color/white"
        android:textAppearance="?android:attr/textAppearanceSmall"/>

    <ListView
        android:id="@+id/lv_messages_updates"
        android:layout_width="240dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/tvMessagesCategory"
        android:layout_gravity="start"
        android:background="@android:color/transparent"
        android:choiceMode="singleChoice"
        android:divider="@color/divider_orange"
        android:dividerHeight="2dp" >
    </ListView>

    <TextView
        android:id="@+id/tvEvenetsCategory"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:gravity="right"
        android:layout_marginRight="5dp"
        android:layout_below="@id/lv_messages_updates"
        android:text="עדכון הודעות"
        android:textSize="15dp"
        android:textColor="@android:color/white"
        android:textAppearance="?android:attr/textAppearanceSmall"/>

    <ListView
        android:id="@+id/lv_events_updates"
        android:layout_width="240dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/tvEvenetsCategory"
        android:layout_gravity="start"
        android:background="@android:color/transparent"
        android:choiceMode="singleChoice"
        android:divider="@color/divider_orange"
        android:dividerHeight="2dp" >
    </ListView>

    <TextView
        android:id="@+id/tvOptionsCategory"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:gravity="right"
        android:layout_marginRight="5dp"
        android:layout_below="@id/lv_events_updates"
        android:text="אפשרויות נוספות"
        android:textSize="15dp"
        android:textColor="@android:color/white"
        android:textAppearance="?android:attr/textAppearanceSmall"/>

    <ListView
        android:id="@+id/lvOptions"
        android:layout_width="240dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/tvOptionsCategory"
        android:layout_gravity="start"
        android:background="@android:color/transparent"
        android:choiceMode="singleChoice"
        android:divider="@color/divider_orange"
        android:headerDividersEnabled="true"
        android:dividerHeight="2dp" >
    </ListView>

</RelativeLayout>

{它只是带有 android.support.v4.widget.DrawerLayout 标签的整个 xml 文件的一部分..}

无论如何,底部有更多按钮我无法触及,因为它不是滚动视图...

我试着用 ScrollView 包裹起来,结果一团糟..

我能做什么?

编辑:

这是我使用线性布局的滚动视图时发生的情况:

这是代码:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/rlBanner">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

 ...everything is the same inside

    </LinearLayout>
</ScrollView>

好的,问题是你在滚动视图中有一个列表视图。你有两个主要的选择来处理这个:

  1. 仍然使用滚动视图中的列表视图并解决滚动问题(因为两种布局都有滚动),像这样:

Android list view inside a scroll view

  1. 用自定义线性布局替换列表视图,并将其添加到滚动视图中。还有一些链接建议此选项,因为您将不再有两个可以滚动的视图:

How can I put a ListView into a ScrollView without it collapsing?

Android: Listview inside ScrollView

这里是第二点的实际教程:

http://www.androidhub4you.com/2014/03/android-listview-into-scrollview-issue.html

希望对您有所帮助! :)