NavigationDrawer中的ScrollView中的ListView

时间:2014-06-07 10:50:59

标签: android listview android-fragments android-listview navigation-drawer

请原谅我的错误,因为我不太懂英文。我有个问题。我将ListView放在NavigationDrawer片段中的ScrollView中。我的ListView很不寻常,它没有滚动,因为已经放入ScrollView。这是我的ListView:

package com.vk.app.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ListView;

public class ListViewWithoutScroll extends ListView {

    public ListViewWithoutScroll(Context context) {
        super(context, null);
    }

    public ListViewWithoutScroll(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ListViewWithoutScroll(Context context, AttributeSet attrs,
            int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_MOVE)
            return true;
        return super.dispatchTouchEvent(ev);
    }

}

这段代码运行良好,但我看到了问题:在我看来,当我滚动ListView与我的触摸ScrollView或NavigationDrawer冲突时,这对用户来说不方便,例如:我正在滚动我的ListView而不是这个NavigationDrawer正在隐藏。这有时它可以正常工作,但有时不能。请给我一些关于如何进行的建议。我通过互联网寻求解决方案,但没有找到。另外,请不要给出像ScrollView中不使用ListView等的答案,因为上面描述的方式最适合我。

主要片段:

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.vk.app.MainActivity$PlaceholderFragment" >

    <TextView
        android:id="@+id/section_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>

主要活动:

<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<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="com.vk.app.MainActivity" >

    <!--
     As the main content view, the view below consumes the entire
     space available using match_parent in both dimensions.
    -->

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

    <!--
     android:layout_gravity="start" tells DrawerLayout to treat
     this as a sliding drawer on the left side for left-to-right
     languages and on the right side for right-to-left languages.
     If you're not building against API 17 or higher, use
     android:layout_gravity="left" instead.
    -->


    <!--
     The drawer is given a fixed width in dp and extends the full height of
     the container.
    -->

    <fragment
        android:id="@+id/navigation_drawer"
        android:layout_width="@dimen/navigation_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        class="com.vk.app.fragments.NavigationDrawerFragment" />

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

我的导航抽屉片段:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:context="com.vk.app.fragments.NavigationDrawerFragment" >

        <RelativeLayout
            android:id="@+id/profile_info_menu_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/top_block_menu"
            android:padding="@dimen/image_menu_profile_photo_margin" >

            <RelativeLayout
                android:id="@+id/profile_info_loaded_menu_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="gone" >

                <ImageView
                    android:id="@+id/image_menu_profile_photo"
                    android:layout_width="@dimen/image_menu_profile_photo_width"
                    android:layout_height="@dimen/image_menu_profile_photo_width"
                    android:contentDescription="@string/profile_photo_content_description" />

                <TextView
                    android:id="@+id/menu_profile_name_text"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="@dimen/image_menu_profile_photo_margin"
                    android:layout_toRightOf="@+id/image_menu_profile_photo"
                    android:textSize="@dimen/navigation_drawer_text_size" />
            </RelativeLayout>

            <ProgressBar
                android:id="@+id/profile_info_loading_progress_bar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true" />
        </RelativeLayout>

        <com.vk.app.widget.ListViewWithoutScroll
            android:id="@+id/list_view_menu_items"
            android:layout_width="match_parent"
            android:layout_height="506dp"
            android:layout_below="@+id/profile_info_menu_layout"
            android:background="@color/white"
            android:focusableInTouchMode="false"
            android:scrollbars="none" />
    </RelativeLayout>

</ScrollView>

0 个答案:

没有答案