Android HorizontalScrollView中的ListView和ScrollView中的HorizontalScrollView

Android HorizontalScrollView中的ListView和ScrollView中的HorizontalScrollView,android,listview,Android,Listview,这是my layout.xml: <ScrollView android:id="@+id/scroll_view" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wra

这是my layout.xml:

<ScrollView
    android:id="@+id/scroll_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ListView
            android:id="@+id/list_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:cacheColorHint="@android:color/transparent"
            android:divider="@null"
            android:dividerHeight="0dp" />

        <HorizontalScrollView
            android:id="@+id/h_scroll_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp">

            <LinearLayout
                android:id="@+id/nest_list_view_container"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:orientation="horizontal">
            </LinearLayout>
        </HorizontalScrollView>
    </LinearLayout>
</ScrollView>

有两个列表视图。 第一个列表视图是
列表视图
; 第二个listview动态添加到LinearLayout(
nest\u list\u view\u容器
)中

第一个ListView将使用
setOnTouchListener
方法正常工作,
但是第二个ListView不能用相同的方法滚动,仅响应单击事件。

您不应将ListView保留在ScrollView中。动态更新列表后,ListView本身可滚动。请删除ListView上方的任何视图组,然后重试。

使用recyclerview而不是ListView,并在其中使用以下代码以平滑移动recyclerview:

          android:nestedScrollingEnabled="false"
此外,我更喜欢使用:

       <android.support.v4.widget.NestedScrollView
            android:id="@+id/activity_Recipe_detail_scrollview"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
              <LinearLayout
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                   android:orientation="vertical">
                   // ..
            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>

// ..

在这种情况下,可以在scrollview中添加listview或recyclerview 因为我在我的项目中多次使用它。 例如:

  <android.support.v4.widget.NestedScrollView
            android:id="@+id/activity_Recipe_detail_scrollview"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <LinearLayout
                    android:id="@+id/activity_Recipe_detail_content_container"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:orientation="vertical">

                    <android.support.v7.widget.CardView
                        android:id="@+id/activity_Recipe_detail_hashtag_card"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="@dimen/recipe_detail_card_margin_top"
                        android:layout_marginLeft="32dp"
                        android:layout_marginRight="32dp"
                        android:layout_marginTop="@dimen/recipe_detail_card_margin_top"
                        app:cardBackgroundColor="@android:color/white"
                        app:cardCornerRadius="@dimen/radius_recipe_detail_card"
                        app:cardElevation="1dp"
                        app:contentPadding="16dp">

                        <android.support.v7.widget.RecyclerView
                            android:id="@+id/activity_Recipe_detail_hashtag_list"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            tools:listitem="@layout/hashtag" />
                    </android.support.v7.widget.CardView>

                </LinearLayout>
            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>


您是否检查了此链接:@MavyaSoni是的,但它不起作用。谢谢。你的建议很有用。但是android:nestedScrollingEnabled=“true”对我有效。如果使用nestedScrollView@ujjjwal也可以