Android 导航抽屉中的滚动视图中的ListView

Android 导航抽屉中的滚动视图中的ListView,android,listview,android-fragments,android-listview,navigation-drawer,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;

请原谅我的错误,因为我不太懂英语。我有个问题。我将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时,它与我的touch 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>
<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>

主要活动:

<!-- 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>

和我的导航抽屉片段:

<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>
<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>


Listview不应在scrollView中使用,因为两者都提供滚动。@SohailAziz我已经知道了,但我必须在scrollView中提供类似Listview的内容。没有滚动的替代ListView是什么?你想实现什么?@SohailAziz我想做与ListView相同的事情,但我不需要滚动,它应该能够适应ScrollView。我认为这一决定是由于线性布局,但我不知道具体如何实施。总的来说,我认为谷歌的Android开发者应该提供这样一个机会,就像我经常看到的那样,人们在寻找问题的解决方案时会感到痛苦。所以你取消了列表视图的滚动,现在你有了一个不可滚动的列表视图,你想把它放到一个滚动视图中。。。为什么?为什么不使用一个普通的可滚动的listview。。。?