导航抽屉中的ScrollView

时间:2015-03-02 16:01:03

标签: android scrollview navigation-drawer

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

此导航抽屉的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时发生的事情: enter image description here

这是代码:

<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 个答案:

答案 0 :(得分:1)

好的,问题是你在scrollview中有一个listview。您有两个主要选项来处理这个问题:

  1. 仍然使用scrollview中的listview并解决滚动问题(因为两个布局都有滚动),如下所示:
  2. Android list view inside a scroll view

    1. 使用自定义线性布局替换列表视图,并在滚动视图中添加此列表视图。还有一些链接建议使用此选项,因为您将不再有两个可以滚动的视图:
    2. 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

      希望这有帮助! :)