【问题标题】:ListView in a HorizontalScrollView in AndroidAndroid中Horizo​​ntalScrollView中的ListView
【发布时间】:2009-12-10 04:23:58
【问题描述】:

我在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>

【问题讨论】:

  • 不适合我...列表垂直显示

标签: android listview horizontalscrollview


【解决方案1】:

我会尝试让您的 ListView 不可见,直到您致电 notifyDataSetChanged()

<ListView android:id="@+id/my_list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:visibility="gone"/>

然后在代码中:

_myListAdapter.notifyDataSetChanged();
ListView listView = (ListView) findViewById(R.id.my_list);
listView.setVisibility(View.VISIBLE);

不确定这是否可行……不过值得一试。

【讨论】:

  • 是的。我这样做了,但我最初并没有设置为“消失”,只是“不可见”。它确实解决了问题,但我不知道。似乎是一种解决方法。也许我会向 Android 团队提交一个错误 - 我在文档中找不到任何说明我做错了的内容。谢谢你的回答。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-09
  • 2021-07-02
  • 1970-01-01
  • 2014-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多