屏幕冻结 - 滚动视图 android 中的列表视图
我阅读了几篇博客\so\论坛帖子,发现将 ListView 放入 ScrollView 中显然存在问题。但在某个地方,我发现如果我在滚动视图中放置线性布局(作为列表),它应该可以工作,现在它可以工作。下面是我的xml。 但列表不会向上\向下滚动,它被冻结了...... 知道为什么吗?
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:fillViewport="true">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="horizontal">
<ListView android:id="@+id/listView1" android:layout_width="100dp"
android:layout_height="wrap_content" android:background="@color/white"
android:cacheColorHint="#00000000" />
<HorizontalScrollView android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView android:id="@+id/listView2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:background="@color/white"
android:cacheColorHint="#00000000" />
</HorizontalScrollView>
</LinearLayout>
</LinearLayout>
</ScrollView>
i read several blogs\so\forum posts and see that there is clearly an issue with putting a ListView in a ScrollView. But somewhere i found that it should work if i put a linear layout(which as the list) in the scrollview and now it will work. below is my xml.
but the lists do not scroll up\down, its frozen...
any idea why?
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:fillViewport="true">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="horizontal">
<ListView android:id="@+id/listView1" android:layout_width="100dp"
android:layout_height="wrap_content" android:background="@color/white"
android:cacheColorHint="#00000000" />
<HorizontalScrollView android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView android:id="@+id/listView2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:background="@color/white"
android:cacheColorHint="#00000000" />
</HorizontalScrollView>
</LinearLayout>
</LinearLayout>
</ScrollView>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
首先ListView不应该插入到ScrollView中。将 ListView 放入 LinearLayout 中可以显示它,但 ScrollView 会吃掉所有垂直滚动事件,因此您的 ListView 永远不会收到任何触摸事件。
您可能想玩 ViewGroup.html #onInterceptTouchEvent(android.view.MotionEvent)。
First of all ListView should not be inserted into the ScrollView. Putting your ListView inside the LinearLayout allows you to display it, but ScrollView eats all vertical scrolling events, so your ListView never receives any touch events.
You may want to play with ViewGroup.html#onInterceptTouchEvent(android.view.MotionEvent).
把它们放进去
put them inside
我修改了 xml 布局,还修改了 onScroll 侦听器。现在工作得很好。
I modified the xml layout and also modified the onScroll listener. It works perfectly fine now.
如果您在 Scrollview 中使用 Listview - 滚动冻结
如果您在 Scrollview 中使用 Recyclerview - 滚动冻结
为什么屏幕冻结:Recyclerview 具有滚动行为和滚动行为你试图放入一个Scrollview[已经具有滚动行为]
所以它会混淆要跟随哪个滚动
使用此代码禁用recyclerview的滚动,以便它仅使用SCROLLVIEW滚动
注意:如果您使用多个recyclerview /listviews 在同一活动中
您需要禁用所有 recyclerviews/listviews 的滚动
If you use Listview inside Scrollview - Scroll freezes
If you use Recyclerview inside Scrollview - Scroll freezes
Why screen freezes : Recyclerview has scroll behaviour & your trying to put into one Scrollview[Which already has the scroll behaviour]
So it confuses which scroll to follow
Use this code to disable scroll for recyclerview so it uses only SCROLLVIEW scrolls
Note : If you use multiple recyclerviews/listviews in same activity
you need to disable scrolls for all recyclerviews/listviews