Android : WebView getScrollY always returns 0

on Thursday, July 3, 2014


I have a WebView in my fragment layout, and I find it inside onCreateView():



mSummaryFrame = (WebView) rootView.findViewById(R.id.summary_frame);


I also load HTML into the WebView using mSummaryFrame.loadDataWithBaseURL(). Everything works fine until I try to save the scroll position for screen rotations in onSaveInstanceState():



int contentHeight = mSummaryFrame.getContentHeight();
int scrollY = mSummaryFrame.getScrollY();

float scrollPercent = (float) scrollY / (float) contentHeight;

outState.putFloat("scrollPercent", scrollPercent);


For some reason mSummaryFrame.getScrollY() always returns 0, and then I can't restore how far the page has been scrolled after the screen rotation. Why would this be happening?


0 comments:

Post a Comment