这是我的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>有两个列表视图。第一个列表视图是list_view;第二个listview动态地添加到LinearLayout(nest_list_view_container)中。
第一个ListView将与setOnTouchListener方法一起正常工作,但是第二个ListView不能使用相同的方法滚动,只能响应单击事件。
发布于 2016-12-23 10:19:25
使用回收视图而不是列表视图,并在其中使用此代码来平稳地移动回收视图:
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>在这种情况下
发布于 2016-12-23 10:28:02
在滚动视图中添加列表视图或回收视图是绝对可能的,因为我在我的项目中多次使用它。举个例子:
<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>发布于 2016-12-23 10:14:28
您不应该将ListView保存在ScrollView.ListView本身上,在正在更新的列表上滚动,dynamically.Remove,ListView之上的任何ViewGroup,然后再试一次。
https://stackoverflow.com/questions/41299226
复制相似问题