【问题标题】:How to prevent scrollview from scrolling on adding new view to the content layout如何防止滚动视图在向内容布局添加新视图时滚动
【发布时间】:2020-02-12 19:04:01
【问题描述】:

我在滚动视图中有一个 LinearLayout,当我向 LinearLayout 滚动视图添加新内容时,滚动视图会滚动到该内容,然后跳回顶部。 我如何防止这种情况发生,即我希望滚动视图保持在当前位置,而不管添加或删除新内容。 我试过了

  1. 将 descendantFocusability 设置为 blocksDescendants
  2. 在添加新视图之前禁用滚动视图

【问题讨论】:

    标签: android android-layout android-scrollview


    【解决方案1】:

    您可以通过制作自己的 LinearLayout 并覆盖 protected void onSizeChanged 来获取 LinearLayout 的 OnSizeChanged 事件。确定oldh和h的差异,然后scrollview.setScrollY来弥补差异。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-25
      相关资源
      最近更新 更多