Mukul
Mukul

Reputation: 141

How to prevent scrollview from scrolling on adding new view to the content layout

I have a LinearLayout inside a scrollview, When i add new content to the LinearLayout scrollview scrolls to that content and then jumps back to top. How do i prevent this i.e. I want the scrollview to stay at the current position irrespective of addition or removal of new content. I've tried

  1. Setting descendantFocusability to blocksDescendants
  2. Diable scrollview before adding new views

Upvotes: 3

Views: 830

Answers (1)

RyanCheu
RyanCheu

Reputation: 3552

You can get the OnSizeChanged events of the LinearLayout by making your own LinearLayout and overriding protected void onSizeChanged. Determine the difference in oldh and h, and then scrollview.setScrollY to compensate for the difference.

Upvotes: 3

Related Questions