Android: Preventing scrollview from scrolling automatically when hiding/showing views within it. How can I fix this?

  • Thread starter Thread starter AC Question
  • Start date Start date
A

AC Question

Android: Preventing scrollview from scrolling automatically when hiding/showing views within it

I'm having a scrollview in my layout with a lot of views.

Within scrollview I'm having this layout for one particular item

<scrollview>
...
<FrameLayout>
<View1/>
<View2 hidden/>
</FrameLayout>
...
</scrollview>

____________ ____________
| | | |
| | | View 2 |
| View 1 | | |
| | | |
| | ----------------------
-----------------------
I'm animating the views like this:

On some action: Sliding the view View1 out and View2 in (hiding the view1)
On some other action: Sliding the view View2 out and View1 in (hiding the view2)
My problem is: On doing these actions, the scrollview is scrolling automatically (which is not looking good).

Probably the cause is : changing the visibility of the views.

I tried two things:

Disabling vertical scrolling but that didn't help
Remembering the scrollY in onAnimationStart and restoring this scroll position in onAnimationEnd - problem with this approach is, its visible clearly that the scrollview moved (although it moved really fast).

This idea came to my mind, but i didn't know how to implement this: Keeping the upper views (wrt the framelayout) as it is and shifting the lower views to fill up the space, so that vertical scrollY value remains the same.

Is there a way I can implement this? If not, is there any other way i can achieve this?
 

Latest posts

Forum statistics

Threads
956,230
Messages
6,967,042
Members
3,163,488
Latest member
katmajic