Android 中 HorizontalScrollView 中的 ListView
我在 HorizontalScrollView
中有一个 ListView
,除了初始加载之外,它工作得很好。我正在从 Web 服务加载列表视图的数据,因此我创建了一个线程来执行此操作。获得数据后,只需调用 _myListAdapter.notifyDataSetChanged();
,数据就会在 ListView
中可见。但如果 ListView
距离屏幕较远,则包含的 HorizontalScrollView
将自动滚动以使该 ListView
可见。如何在不使 ListView
滚动到当前视图的情况下调用 notifyDataSetChanged
?
以下是我如何拥有布局 XML 文件的想法:
<HorizontalScrollView
android:id="@+id/my_scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none">
<LinearLayout android:id="@+id/my_layout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal">
<ListView android:id="@+id/my_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
</HorizontalScrollView>
I have an ListView
inside a HorizontalScrollView
and it works perfectly fine, except for the initial load. I'm loading the data for the list view from a web service so I created a thread to do that. Once I have the data, I simply call _myListAdapter.notifyDataSetChanged();
and the data becomes visible in the ListView
. But if the ListView
is far off the screen, the containing HorizontalScrollView
will automatically scroll to make this ListView
visible. How can I call notifyDataSetChanged
without making the ListView
scroll into the current view?
Here's an idea of how I have my layout XML file:
<HorizontalScrollView
android:id="@+id/my_scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none">
<LinearLayout android:id="@+id/my_layout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal">
<ListView android:id="@+id/my_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
</HorizontalScrollView>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会尝试让您的 ListView 不可见,直到您调用
notifyDataSetChanged()
为止。然后在代码中:
不确定这是否有效......不过值得一试。
I would try making your ListView invisible until after you've called
notifyDataSetChanged()
.Then in the code:
Not sure if this will work... worth a shot, though.