【问题标题】:Scrollview doesn't scroll after resizing it's child using animation使用动画调整其子项的大小后,Scrollview 不滚动
【发布时间】:2015-05-03 23:09:21
【问题描述】:

我在 ScrollView 中有一个 LinearLayout。在某些时候,我折叠并展开 LinearLayout。之后,滚动视图确实滚动。有什么想法吗?

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="false">

    <LinearLayout
        android:id="@+id/detailsView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:visibility="visible"
        >
........
</LinearLayout>
</ScrollView>

使用 ValueAnimator 在 LinearLayout 的 LayoutParams(高度)上完成展开和折叠。

更新:我认为重要的是它在动画展开/折叠后分解。直到它工作正常。

更新2:为了再次展开,我测量了预期的高度如下:

  int expectedHeight = detailsView.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

并动画扩张到那个高度。这测量到 2000+ 的高度,而不是预期的 800 左右。因此大小相等,并且滚动视图没有滚动,尽管它没有显示完整的层次结构。

作为快速修复,我在折叠之前保存当前高度,并将其用作展开时的目标高度。问题是,这可以自动完成而不节省脏高度吗?

【问题讨论】:

  • 我觉得截图没什么用——只有两个视图,一个在另一个里面,不能通过截图显示动态。

标签: android scrollview android-animation


【解决方案1】:

您的滚动视图是android:layout_height="wrap_content",只需将其设为match_parent。我不确定,但你也可以删除 android:fillViewport

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <LinearLayout
        android:id="@+id/detailsView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:visibility="visible"
        >
........
</LinearLayout>
</ScrollView>

【讨论】:

  • scrollview 仅在 content size 为 > 作为scrollview 尺寸时才会滚动,能否发一份前后的截图?
  • 感谢您的评论,我想我明白问题出在哪里了——在调试时,我想到了同样的事情:在崩溃之前,LinearLayout 的高度是 818,展开之后是 2257。所以,当我展开 LinearLayout 时,ScrollView 也会展开,因此不会滚动任何内容。现在将检查 ScrollView 的大小。
猜你喜欢
  • 1970-01-01
  • 2023-04-02
  • 2013-11-02
  • 2016-01-14
  • 2016-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多