2

I have a LinearLayout inside a ScrollView. At some point I collapse and expand the LinearLayout. After that the scrollview does scroll. Any ideas?

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

Expand and collapse is done using ValueAnimator over LayoutParams (height) of the LinearLayout.

Update: I think important is that it breaks down after animated expansion/collapse. Until that it works fine.

Update 2: For expanding again, I measured the expected height as follows:

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

and animate expansion to that height. This measured the height to 2000+ instead of expected 800 something. Thus the sizes were equal and scrollview didn't scroll, although it didn't show the full hierarchy.

As a quick-fix I save the current height before collapsing and use it as the target height on expanding. The question is, can this be done automatically without dirty-height saving?

1
  • I think screenshot is useless - just two views, one inside the other, can't show dynamics by the screenshot.
    – khusrav
    May 3, 2015 at 9:56

1 Answer 1

0

your scrollview is android:layout_height="wrap_content" just make it match_parent. I'm not sure but you can remove android:fillViewport too

<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>
2
  • 1
    the scrollview only scroll if content size is > as the scrollview size, can you send a screenshot of before & after please ? May 3, 2015 at 11:40
  • Thank you for your comment, I think I understood what was the issue - was debugging and same thing crossed my mind: before the collapse, LinearLayout's height is 818, after the expansion it is 2257. So, when I expand LinearLayout, ScrollView gets expanded, too, thus not scrolling anything. Will check for ScrollView size now.
    – khusrav
    May 3, 2015 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.