Can't scroll over image in webview

前端 未结 4 628
北海茫月
北海茫月 2021-01-21 22:25

I developed a webview app for android and iOS. I noticed that I can\'t scroll over a specific html element in the android app, while it works on iOS.

This is the website

4条回答
  •  失恋的感觉
    2021-01-21 23:15

    At first remove this entire section,

    @Override
            public void onPageFinished(WebView view, String url)
            {
                super.onPageFinished(view, url);
    
                //blizzView.Settings.setSupportZoom(true);
    
                blizzView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
    
                blizzView.getSettings().setSupportZoom(true);
                blizzView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
    
                blizzView.loadUrl(
                        "javascript:(function() {"
    
    
                                //+ "jQuery('.logo').remove();" //Einige Funktionen wie z.B. alert() sind scheinbar aus Sicherheits-/Missbrauchsgründen nicht verfügbar; jQuery kann man natürlich nur nutzen wenn es eingebunden ist. Möglicherweise kann man es auch selbst einbinden.
                        + "})()"
                );
    
                // Hide/Show back button
                backButton = findViewById(R.id.backButton);
                backButton.setEnabled(blizzView.canGoBack());
    
                if (blizzView.canGoBack()) {
                    backButton.setVisibility(View.VISIBLE);
                } else {
                    backButton.setVisibility(View.INVISIBLE);
                }
    
                blizzView.setVerticalScrollBarEnabled(true);
                blizzView.setHorizontalScrollBarEnabled(true);
    
            }
    

    because you can't rely on onPageFinished instead you should implement shouldOverrideUrlLoading. I'll post my complete code here.

    public class TempWebActivity extends AppCompatActivity {
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_temp_web);
    
        WebView webView = findViewById(R.id.wv_scroller);
        webView.getSettings().setJavaScriptEnabled(true);
    
        webView.loadUrl("https://www.blizz-z.de");
    
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        }
    }
    

    Here's the activity layout

    
    
    
    
    
    
    

    The key to achieve this is to use a ScrollView wrapper with WebView if some Javascript can intercept some touch events. Also make sure that you keep the height of WebView as wrap_content. Happy coding bro! :)

提交回复
热议问题