首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ListView在HorizontalScrollView中,HorizontalScrollView在ScrollView中

ListView在HorizontalScrollView中,HorizontalScrollView在ScrollView中
EN

Stack Overflow用户
提问于 2016-12-23 10:02:40
回答 3查看 127关注 0票数 3

这是我的layout.xml:

代码语言:javascript
复制
<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>

有两个列表视图。第一个列表视图是list_view;第二个listview动态地添加到LinearLayout(nest_list_view_container)中。

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

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-12-23 10:19:25

使用回收视图而不是列表视图,并在其中使用此代码来平稳地移动回收视图:

代码语言:javascript
复制
          android:nestedScrollingEnabled="false"

此外,我更喜欢使用:

代码语言:javascript
复制
       <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>

在这种情况下

票数 0
EN

Stack Overflow用户

发布于 2016-12-23 10:28:02

在滚动视图中添加列表视图或回收视图是绝对可能的,因为我在我的项目中多次使用它。举个例子:

代码语言:javascript
复制
  <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>
票数 0
EN

Stack Overflow用户

发布于 2016-12-23 10:14:28

您不应该将ListView保存在ScrollView.ListView本身上,在正在更新的列表上滚动,dynamically.Remove,ListView之上的任何ViewGroup,然后再试一次。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41299226

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档