Android WebView Video after closing fullscreen view, webview auto scrolls

梦想与她 提交于 2020-03-21 11:59:08

问题


I am using WebView to display a webpage having text as well as video content.

It loads & display video correctly as expected.

But when I go to full screen view of video ( I implemeted full screen video view as given here ) and then come back to WebView, WebView autoscroll in some amount.

How can I fix that?

Please suggest some idea/link.


回答1:


I am using a compatible ScrollChangedListener already. So I've decided to scroll the view back in this listener during a period after onHideCustomView.

webview:

public interface OnScrollChangedListener {
    void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY);
}

    public void SafeScrollTo(int x, int y) {
        OnScrollChangedListener mScrollChanged = mOnScrollChangeListener;
        mOnScrollChangeListener =null;
        scrollTo(x, y);
        mOnScrollChangeListener =mScrollChanged;
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        if(mOnScrollChangeListener !=null)
            mOnScrollChangeListener.onScrollChange(this,l,t,oldl,oldt);
    }

    public void setOnScrollChangedListener(OnScrollChangedListener onSrollChangedListener) {
        mOnScrollChangeListener =onSrollChangedListener;
    }

    OnScrollChangedListener mOnScrollChangeListener;

Activity:

mWebview.setOnScrollChangedListener((v, x, y, oldx, oldy) -> {
                ArticleWebView webview = (ArticleWebView) v;
                if(CustomViewHideTime>0 && System.currentTimeMillis()-CustomViewHideTime<350){
                    webview.SafeScrollTo(oldx, oldy);
                    return;
                }});

WebChromeClient:

        @Override
        public void onHideCustomView() {
            CustomViewHideTime = System.currentTimeMillis();
            //todo delay and set CustomViewHideTime to 0
        }

This can work just fine.



来源:https://stackoverflow.com/questions/41331940/android-webview-video-after-closing-fullscreen-view-webview-auto-scrolls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!