I have a page, including WebView. I had android:configChanges="...|orientation|screenSize"
in manifest and in worked perfectly well: I scroll view to a particular text, and when screen orientation changes,
the WebView is positioned to the same text on the top (this is not same as preserving ScrollY, because
of changed width).
Now I changed the design and have different layouts for horizontal and vertical orientation. I prefer to remove 'orientation|screenSize' for the activity to allow reconstructing the page when orientation changes. Everything works fine, but I need to restore the text offset manually.
The closest I could find is getOffsetForPosition(getScrollX(), getScrollY())
for saving offset and
bringPointIntoView(offset)
for restoring offset, however these function are not backward-compatible:
getOffsetForPosition wants API 3+, while bringPointIntoView requires API 14+ (!). In addition they apply to TextView and may be inaccurate with WebView because of HTML tags.
Tried WebView.saveState
and WebView.restoreState
(called after the page has been loaded). Doesn't seem to work for me.
Yes, I can get calculate scroll position using Paint and FontMetrics, but this is a "dirty trick". Ideally, I prefer to get all parameters from the system and keep the code as much backward compatible as possible.