Maintain WebView content scroll position on orientation change

前端 未结 8 770
隐瞒了意图╮
隐瞒了意图╮ 2020-12-23 02:04

The browsers in Android 2.3+ do a good job at maintaining the scrolled position of content on an orientation changed.

I\'m trying to achieve the same thing for a We

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-23 02:17

    In the partial solution described in the original post, you can improve the solution if change the following code

    private float calculateProgression(WebView content) {
        float contentHeight = content.getContentHeight();
        float currentScrollPosition = content.getScrollY();
        float percentWebview = currentScrollPosition/ contentHeight;
        return percentWebview;
    }
    

    due to the top position of the component, when you are using content.getTop () is not necessary; So what it does is add to the actual position of the scroll Y position where the component is located with respect to it parent and runs down the content. I hope my explanation is clear.

提交回复
热议问题