无法在网络视图中滚动图像

2024-04-25

我为 Android 和 iOS 开发了一个 webview 应用程序。我注意到我无法滚动 Android 应用程序中的特定 html 元素,而它可以在 iOS 上运行。

这是website https://www.blizz-z.de/flex-schnell-fliesenkleber-proflex-fix.html.

问题出在产品图片上,但仅出现在产品详细信息页面上,您可以在其中购买产品并将其放入购物车......

HTML

<div class="magic-slide mt-active" data-magic-slide="zoom">
    <a id="MagicZoomPlusImage286" class="MagicZoom" href="https://www.blizz-z.de/media/catalog/product/cache/2/image/0dc2d03fe217f8c83829496872af24a0/f/l/fliesenkleber-proflex-fix-1303_1.jpg" data-options="selectorTrigger:hover;textHoverZoomHint:Hovern zum Zoomen;textClickZoomHint:Berühren zum Zoomen;textExpandHint:Vergrößern;"
        data-mobile-options="textHoverZoomHint:Berühren zum Zoomen;textClickZoomHint:Doppeltippe zum Zoomen;textExpandHint:Vergrößern;">
        <figure class="mz-figure mz-hover-zoom mz-ready"><img itemprop="image" src="https://www.blizz-z.de/media/catalog/product/cache/2/image/450x450/0dc2d03fe217f8c83829496872af24a0/f/l/fliesenkleber-proflex-fix-1303_1.jpg" alt="Fliesenkleber proflex fix Schnell-Fliesenkleber - nach 3 Stunden begehbar"
                style="max-width: 450px; max-height: 450px;">
            <div class="mz-lens" style="top: 0px; transform: translate(-10000px, -10000px); width: 122px; height: 122px;"><img src="https://www.blizz-z.de/media/catalog/product/cache/2/image/450x450/0dc2d03fe217f8c83829496872af24a0/f/l/fliesenkleber-proflex-fix-1303_1.jpg" style="position: absolute; top: 0px; left: 0px; width: 349px; height: 349px; transform: translate(-1px, -132px);"></div>
            <div
                class="mz-loading"></div>
<div class="mz-hint mz-hint-hidden"><span class="mz-hint-message">Vergrößern</span></div>
</figure>
</a>
</div>

如果我从智能手机 Chrome 浏览器访问该网站,那么它就可以工作,所以这一定是 webview 中的错误?

该图像是一个滑块,我可以左右滑动,但如果滚动图像则无法向下滚动页面。

全屏Activity.java:

package de.blizz_z.onlineshop;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Bitmap;
import android.webkit.URLUtil;
import android.net.Uri;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Build;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebChromeClient;
import android.widget.Button;
import android.util.Log;
import android.webkit.HttpAuthHandler;
import android.webkit.ValueCallback;

/**
 * An example full-screen activity that shows and hides the system UI (i.e.
 * status bar and navigation/system bar) with user interaction.
 */
public class FullscreenActivity extends AppCompatActivity
{
    private WebView blizzView;
    private Button backButton;
    private String website;

    /**
     * Whether or not the system UI should be auto-hidden after
     * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
     */
    private static final boolean AUTO_HIDE = true;

    /**
     * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
     * user interaction before hiding the system UI.
     */
    private static final int AUTO_HIDE_DELAY_MILLIS = 3000;

    /**
     * Some older devices needs a small delay between UI widget updates
     * and a change of the status and navigation bar.
     */
    private static final int UI_ANIMATION_DELAY = 300;
    private final Handler mHideHandler = new Handler();
    private final Runnable mHidePart2Runnable = new Runnable()
    {
        @SuppressLint("InlinedApi")
        @Override
        public void run() {

        }
    };

    private final Runnable mShowPart2Runnable = new Runnable()
    {
        @Override
        public void run() {
            // Delayed display of UI elements
            ActionBar actionBar = getSupportActionBar();
            if (actionBar != null) {
                actionBar.show();
            }
        }
    };
    private boolean mVisible;
    private final Runnable mHideRunnable = new Runnable() {
        @Override
        public void run() {
            hide();
        }
    };

    /**
     * Touch listener to use for in-layout UI controls to delay hiding the
     * system UI. This is to prevent the jarring behavior of controls going away
     * while interacting with activity UI.
     */
    private final View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener()
    {
        @Override
        public boolean onTouch(View view, MotionEvent event)
        {

            Log.i("debug_log", "touch");

            if (AUTO_HIDE) {
                delayedHide(AUTO_HIDE_DELAY_MILLIS);
            }

            int x = (int) event.getX();
            int y = (int) event.getY();

            Log.i("debug_log", "moving: (" + x + ", " + y + ")");

            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    Log.i("debug_log", "touched down");
                    break;
                case MotionEvent.ACTION_MOVE:
                    Log.i("debug_log", "moving: (" + x + ", " + y + ")");
                    break;
                case MotionEvent.ACTION_UP:
                    Log.i("debug_log", "touched up");
                    break;
            }

            return true;
        }

    };

    @SuppressLint("ClickableViewAccessibility")
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fullscreen);

        mVisible = true;
        website = "https://www.blizz-z.de";
        blizzView = findViewById(R.id.blizzView);

        WebSettings settings = blizzView.getSettings();
        settings.setJavaScriptEnabled(true);

        // https://developer.android.com/reference/android/webkit/WebViewClient
        blizzView.setWebViewClient(new WebViewClient() {

            @Override
            public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
                super.onReceivedHttpError(view, request, errorResponse);

                Log.i("debug_log", errorResponse.getReasonPhrase());
            }

            @Override
            public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm)
            {
                super.onReceivedHttpAuthRequest(view, handler, host, realm);

                view.setHttpAuthUsernamePassword(host, realm, "macs", "20macs14");
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon)
            {
                // check here the url
                if (url.endsWith(".pdf")) {
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    startActivity(browserIntent);
                } else {
                    super.onPageStarted(view, url, favicon);
                }
            }

            @Override
            // Notify the host application that a page has finished loading.
            public void onPageFinished(WebView view, String url)
            {
                super.onPageFinished(view, url);

                 // 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);
                }

                js(blizzView, "jQuery(document).ready(function() {"

                                        + "setInterval(function() {"
                                            + "jQuery('#myInput').css('background', '#'+(Math.random()*0xFFFFFF<<0).toString(16));"

                                            + "jQuery('a').each(function() {"
                                                + "jQuery(this).removeAttr('download');"
                                            + "});"
                                        + "}, 1000);"
                                    + "});");

            }

            // Give the host application a chance to take control when a URL is about to be loaded in the current WebView.
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                Log.i("debug_log", "shouldOverrideUrlLoading");

                //view.loadDataWithBaseURL("https://www.blizz-z.de", );

            // Allow download of .pdf files
                if (url.endsWith(".pdf")) {
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                    // if want to download pdf manually create AsyncTask here
                    // and download file
                    return true;
                }

            // Also allow urls not starting with http or https (e.g. tel, mailto, ...)
                if( URLUtil.isNetworkUrl(url) ) {
                    return false;
                } else {
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                }

                return true;
            }

        });

        blizzView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                int x = (int) event.getX();
                int y = (int) event.getY();

                //WebView.HitTestResult hr = blizzView.getHitTestResult();
                //Log.i("debug_log", "getExtra = "+ hr.getExtra() + " Type= " + hr.getType());

                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        Log.i("debug_log", "touched down");
                        break;
                    case MotionEvent.ACTION_MOVE:
                        Log.i("debug_log", "moving: (" + x + ", " + y + ")");
                        break;
                    case MotionEvent.ACTION_UP:
                        Log.i("debug_log", "touched up");
                        break;
                }

                return false;
            }

        });

        // URL laden:
        blizzView.loadUrl(website);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState)
    {
        Log.i("debug_log", "onPostCreate");
        super.onPostCreate(savedInstanceState);

        // Trigger the initial hide() shortly after the activity has been
        // created, to briefly hint to the user that UI controls
        // are available.
        delayedHide(100);
    }

    private void toggle()
    {
        if (mVisible) {
            hide();
        } else {
            show();
        }
    }

    private void hide()
    {
        // Hide UI first
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }
        mVisible = false;

        // Schedule a runnable to remove the status and navigation bar after a delay
        mHideHandler.removeCallbacks(mShowPart2Runnable);
        mHideHandler.postDelayed(mHidePart2Runnable, UI_ANIMATION_DELAY);
    }

    @SuppressLint("InlinedApi")

    private void show()
    {
        // Show the system bar
        mVisible = true;

        // Schedule a runnable to display UI elements after a delay
        mHideHandler.removeCallbacks(mHidePart2Runnable);
        mHideHandler.postDelayed(mShowPart2Runnable, UI_ANIMATION_DELAY);
    }

    /**
     * Schedules a call to hide() in delay milliseconds, canceling any
     * previously scheduled calls.
     */
    private void delayedHide(int delayMillis)
    {
        mHideHandler.removeCallbacks(mHideRunnable);
        mHideHandler.postDelayed(mHideRunnable, delayMillis);
    }

    public void js(WebView view, String code)
    {
        String javascriptCode = "javascript:" + code;
        if (Build.VERSION.SDK_INT >= 19) {
            view.evaluateJavascript(javascriptCode, new ValueCallback<String>() {

                @Override
                public void onReceiveValue(String response) {
                    Log.i("debug_log", response);
                }
            });
        } else {
            view.loadUrl(javascriptCode);
        }
    }

    // Event Listener ------------------------------------------------------------------------------

            public void goBack(android.view.View view)
            {
                blizzView.goBack();
            }

        // If back button of smartphone is pressed, then go back in browser history
            @Override
            public boolean onKeyDown(int keyCode, KeyEvent event)
            {
                Log.i("debug_log", "KeyDown");
                if (event.getAction() == KeyEvent.ACTION_DOWN) {
                    switch (keyCode) {
                        case KeyEvent.KEYCODE_BACK:
                            if (blizzView.canGoBack())
                                blizzView.goBack();
                            else
                                finish();
                            return true;
                    }
                }

                return super.onKeyDown(keyCode, event);
            }

}

活动_全屏.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="visible"
    tools:context="de.blizz_z.onlineshop.FullscreenActivity">

    <WebView
        android:id="@+id/blizzView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:keepScreenOn="true"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

    </WebView>

    <Button
        android:id="@+id/backButton"
        android:layout_width="90dp"
        android:layout_height="39dp"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginBottom="16dp"
        android:background="#F5EA01"
        android:enabled="false"
        android:onClick="goBack"
        android:text="Zurück"
        android:visibility="invisible"
        app:layout_constraintBottom_toBottomOf="@+id/blizzView"
        app:layout_constraintStart_toStartOf="@+id/blizzView" />

</android.support.constraint.ConstraintLayout>

你有两个选择

选项一

通过为 Web 视图上的触摸事件创建自定义侦听器。 我已经修改了@fernandohur对此问题的回答中的片段post https://stackoverflow.com/questions/13095494/how-to-detect-swipe-direction-between-left-right-and-up-down#26387629以匹配您的场景。

创建一个新类(OnSwipeListener.java)

import android.view.GestureDetector;
import android.view.MotionEvent;

public class OnSwipeListener extends GestureDetector.SimpleOnGestureListener {

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

    // Grab two events located on the plane at e1=(x1, y1) and e2=(x2, y2)
    // Let e1 be the initial event
    // e2 can be located at 4 different positions, consider the following diagram
    // (Assume that lines are separated by 90 degrees.)
    //
    //
    //         \ A  /
    //          \  /
    //       D   e1   B
    //          /  \
    //         / C  \
    //
    // So if (x2,y2) falls in region:
    //  A => it's an UP swipe
    //  B => it's a RIGHT swipe
    //  C => it's a DOWN swipe
    //  D => it's a LEFT swipe
    //

    float x1 = e1.getX();
    float y1 = e1.getY();

    float x2 = e2.getX();
    float y2 = e2.getY();

    Direction direction = getDirection(x1,y1,x2,y2);
    return onSwipe(direction, velocityX, velocityY);
}

/** Override this method. The Direction enum will tell you how the user swiped. */
public boolean onSwipe(Direction direction, float velocityX, float velocityY){
    return false;
}

/**
 * Given two points in the plane p1=(x1, x2) and p2=(y1, y1), this method
 * returns the direction that an arrow pointing from p1 to p2 would have.
 * @param x1 the x position of the first point
 * @param y1 the y position of the first point
 * @param x2 the x position of the second point
 * @param y2 the y position of the second point
 * @return the direction
 */
public Direction getDirection(float x1, float y1, float x2, float y2){
    double angle = getAngle(x1, y1, x2, y2);
    return Direction.fromAngle(angle);
}

/**
 *
 * Finds the angle between two points in the plane (x1,y1) and (x2, y2)
 * The angle is measured with 0/360 being the X-axis to the right, angles
 * increase counter clockwise.
 *
 * @param x1 the x position of the first point
 * @param y1 the y position of the first point
 * @param x2 the x position of the second point
 * @param y2 the y position of the second point
 * @return the angle between two points
 */
public double getAngle(float x1, float y1, float x2, float y2) {

    double rad = Math.atan2(y1-y2,x2-x1) + Math.PI;
    return (rad*180/Math.PI + 180)%360;
}


public enum Direction{
    up,
    down,
    left,
    right;

    /**
     * Returns a direction given an angle.
     * Directions are defined as follows:
     *
     * Up: [45, 135]
     * Right: [0,45] and [315, 360]
     * Down: [225, 315]
     * Left: [135, 225]
     *
     * @param angle an angle from 0 to 360 - e
     * @return the direction of an angle
     */
    public static Direction fromAngle(double angle){
        if(inRange(angle, 45, 135)){
            return Direction.up;
        }
        else if(inRange(angle, 0,45) || inRange(angle, 315, 360)){
            return Direction.right;
        }
        else if(inRange(angle, 225, 315)){
            return Direction.down;
        }
        else{
            return Direction.left;
        }

    }

    /**
     * @param angle an angle
     * @param init the initial bound
     * @param end the final bound
     * @return returns true if the given angle is in the interval [init, end).
     */
    private static boolean inRange(double angle, float init, float end){
        return (angle >= init) && (angle < end);
    }
}
}

然后在您的活动中使用...

public class FullscreenActivity extends AppCompatActivity implements View.OnTouchListener {

private WebView blizzView;
private Button backButton;
private String website;
private GestureDetector gestureDetector;

/**
 * Whether or not the system UI should be auto-hidden after
 * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
 */
private static final boolean AUTO_HIDE = true;

/**
 * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
 * user interaction before hiding the system UI.
 */
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;

/**
 * Some older devices needs a small delay between UI widget updates
 * and a change of the status and navigation bar.
 */
private static final int UI_ANIMATION_DELAY = 300;
private final Handler mHideHandler = new Handler();
private final Runnable mHidePart2Runnable = new Runnable()
{
    @SuppressLint("InlinedApi")
    @Override
    public void run() {

    }
};

private final Runnable mShowPart2Runnable = new Runnable()
{
    @Override
    public void run() {
        // Delayed display of UI elements
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.show();
        }
    }
};
private boolean mVisible;
private final Runnable mHideRunnable = new Runnable() {
    @Override
    public void run() {
        hide();
    }
};

@Override
public boolean onTouch(View v, MotionEvent event) {
    Log.d("SWIPER", "onTouch: ");
    gestureDetector.onTouchEvent(event);
    return false;
}
public void scrollUpwards(int scroll_speed) {
    try{
        ObjectAnimator anim = ObjectAnimator.ofInt(blizzView, "scrollY", blizzView.getScrollY(), blizzView.getScrollY() - scroll_speed);
        anim.setDuration(800).start();
    }catch (Exception ex){}
}
public void scrollDownwards(int scroll_speed) {
    try{
       // float maxScrollY = blizzView.getContentHeight() * blizzView.getScale() - blizzView.getMeasuredHeight();
       if(blizzView.getScrollY() <= 100){
           //due to the scroll animation the web page slows down at the top
           //hence we add some extra speed when user is at the top of page to prevent from
           //experiencing delay when scrolling back down
           scroll_speed += 1300;
       }
        ObjectAnimator anim = ObjectAnimator.ofInt(blizzView, "scrollY", blizzView.getScrollY(), blizzView.getScrollY() + scroll_speed);
        anim.setDuration(800).start();
    }catch (Exception ex){}
}
@SuppressLint("ClickableViewAccessibility")
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    gestureDetector=new GestureDetector(this,new OnSwipeListener(){

        @Override
        public boolean onSwipe(Direction direction, float velocityX, float velocityY) {
          //  int scroll_jump_percentage = 60 / 100; //percent of velocity: increase(60) for faster scroll jump
            int scroll_speed =  ((int) Math.abs(velocityY)) * 60 / 100; //percent of velocity: increase(60) for faster scroll jump;
            if (direction==Direction.up){
                //do your stuff
             //   Log.d("SWIPER", "onSwipe: up");
                scrollDownwards(scroll_speed);
                Toast.makeText(getApplicationContext(),"You swiped UP ("+scroll_speed+")",Toast.LENGTH_SHORT).show();

                //we made it!
                return true;
            }
            else if (direction==Direction.down){
                //do your stuff
              //  Log.d("SWIPER", "onSwipe: down");
                scrollUpwards(scroll_speed);
                Toast.makeText(getApplicationContext(),"You swiped DOWN ("+scroll_speed+")",Toast.LENGTH_SHORT).show();

                //we made it!
                return true;
            }

            //nothing to handle here... Mr. WebView can do the rest
            return false;
        }
    });
    mVisible = true;
    website = "https://www.blizz-z.de";
    blizzView = findViewById(R.id.blizzView);
    blizzView.setOnTouchListener(this);
    WebSettings settings = blizzView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setBuiltInZoomControls(false);

    // https://developer.android.com/reference/android/webkit/WebViewClient
    blizzView.setWebViewClient(new WebViewClient() {

        @Override
        public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
            super.onReceivedHttpError(view, request, errorResponse);

           // Log.i("debug_log", errorResponse.getReasonPhrase());
        }

        @Override
        public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm)
        {
            super.onReceivedHttpAuthRequest(view, handler, host, realm);

            view.setHttpAuthUsernamePassword(host, realm, "macs", "20macs14");
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon)
        {
            // check here the url
            if (url.endsWith(".pdf")) {
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(browserIntent);
            } else {
                super.onPageStarted(view, url, favicon);
            }
        }

        @Override
        // Notify the host application that a page has finished loading.
        public void onPageFinished(WebView view, String url)
        {
            super.onPageFinished(view, url);

            // 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);
            }

            js(blizzView, "jQuery(document).ready(function() {"

                    + "setInterval(function() {"
                    + "jQuery('#myInput').css('background', '#'+(Math.random()*0xFFFFFF<<0).toString(16));"

                    + "jQuery('a').each(function() {"
                    + "jQuery(this).removeAttr('download');"
                    + "});"
                    + "}, 1000);"
                    + "});");

            //inject script (this script would remove all event listener from product image
            // that was placed by your MagicZoom Js Library
            //TEMP FIX
           /* blizzView.loadUrl(
                    "javascript:(function() { " +
                            "var slides = document.getElementsByClassName(\"MagicZoom\");\n" +
                            "for(var i = 0; i < slides.length; i++)\n" +
                            "{\n" +
                            "var old_element = slides.item(i);\n" +
                            "old_element.href = '#';\n" +
                            "                var new_element = old_element.cloneNode(true);\n" +
                            "\t\t\t\told_element.parentNode.replaceChild(new_element, old_element);\n" +
                            "       \n" +
                            "   }" +
                            "})()");*/

        }

        // Give the host application a chance to take control when a URL is about to be loaded in the current WebView.
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            Log.i("debug_log", "shouldOverrideUrlLoading");

            //view.loadDataWithBaseURL("https://www.blizz-z.de", );

            // Allow download of .pdf files
            if (url.endsWith(".pdf")) {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                // if want to download pdf manually create AsyncTask here
                // and download file
                return true;
            }

            // Also allow urls not starting with http or https (e.g. tel, mailto, ...)
            if( URLUtil.isNetworkUrl(url) ) {
                return false;
            } else {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            }

            return true;
        }

    });
    // URL laden:
    blizzView.loadUrl(website);
}

@Override
protected void onPostCreate(Bundle savedInstanceState)
{
    Log.i("debug_log", "onPostCreate");
    super.onPostCreate(savedInstanceState);

    // Trigger the initial hide() shortly after the activity has been
    // created, to briefly hint to the user that UI controls
    // are available.
    delayedHide(100);
}

private void toggle()
{
    if (mVisible) {
        hide();
    } else {
        show();
    }
}

private void hide()
{
    // Hide UI first
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.hide();
    }
    mVisible = false;

    // Schedule a runnable to remove the status and navigation bar after a delay
    mHideHandler.removeCallbacks(mShowPart2Runnable);
    mHideHandler.postDelayed(mHidePart2Runnable, UI_ANIMATION_DELAY);
}

@SuppressLint("InlinedApi")

private void show()
{
    // Show the system bar
    mVisible = true;

    // Schedule a runnable to display UI elements after a delay
    mHideHandler.removeCallbacks(mHidePart2Runnable);
    mHideHandler.postDelayed(mShowPart2Runnable, UI_ANIMATION_DELAY);
}

/**
 * Schedules a call to hide() in delay milliseconds, canceling any
 * previously scheduled calls.
 */
private void delayedHide(int delayMillis)
{
    mHideHandler.removeCallbacks(mHideRunnable);
    mHideHandler.postDelayed(mHideRunnable, delayMillis);
}

public void js(WebView view, String code)
{
    String javascriptCode = "javascript:" + code;
    if (Build.VERSION.SDK_INT >= 19) {
        view.evaluateJavascript(javascriptCode, new ValueCallback<String>() {

            @Override
            public void onReceiveValue(String response) {
                Log.i("debug_log", response);
            }
        });
    } else {
        view.loadUrl(javascriptCode);
    }
}

// Event Listener ------------------------------------------------------------------------------

public void goBack(android.view.View view)
{
    blizzView.goBack();
}

// If back button of smartphone is pressed, then go back in browser history
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    Log.i("debug_log", "KeyDown");
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
                if (blizzView.canGoBack())
                    blizzView.goBack();
                else
                    finish();
                return true;
        }
    }

    return super.onKeyDown(keyCode, event);
}

}

选项二

将以下块添加到页面完成WebviewClient 的方法

//This will remove all javascript event listener from affected images. (offending script: MagicZoomPlus.js)
//Setback of this is that images would no longer zoom in when clicked. 

            blizzView.loadUrl(
                    "javascript:(function() { " +
                            "var slides = document.getElementsByClassName(\"MagicZoom\");\n" +
                            "for(var i = 0; i < slides.length; i++)\n" +
                            "{\n" +
                            "var old_element = slides.item(i);\n" +
                            "old_element.href = '#';\n" +
                            "                var new_element = old_element.cloneNode(true);\n" +
                            "\t\t\t\told_element.parentNode.replaceChild(new_element, old_element);\n" +
                            "       \n" +
                            "   }" +
                            "})()");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法在网络视图中滚动图像 的相关文章

随机推荐

  • AWS S3 列表键以字符串开头

    我在 AWS Lambda 函数中使用 python 列出以特定 id 开头的 s3 存储桶中的键 for object in mybucket objects all file name os path basename object k
  • 使用 Electron 和 Systemjs 导入节点模块

    我只是想知道如果系统js在自己的注册表中找不到该模块 是否可以让systemjs使用require remote require nodemodule 我认为当使用带有 typescript 和 commonjs 模块的 Electron
  • 一个包中的多个模块导入一个公共模块

    我正在写一个 python 包 我使用插件的概念 每个插件都是 Worker 类的专门化 每个插件都被编写为模块 脚本 并在单独的进程中生成 由于插件之间的基本共性 例如 所有插件都扩展基类 Worker 插件模块通常如下所示 import
  • 为什么 VBA 中的 GetValue 函数使用单元格“A1”?

    我正在使用此函数从关闭的工作簿中检索值 在此代码的第 8 行中 我不明白为什么使用 A1 整个第 8 行到底发生了什么 我也对 xlR1C1 的论点感到困惑 Private Function GetValue path file sheet
  • 使用 C# 将 JSON 字符串从 Camel 大小写转换为 Pascal 大小写

    我有一个 JSON 字符串 它的密钥采用驼峰式大小写形式 但我需要将密钥转换为帕斯卡式大小写 实际的 JSON 字符串 string jsonString personName firstName Emma lastName Watson
  • Android TabWidget 检测当前选项卡的点击

    我正在尝试找到一种方法 当该选项卡是当前选项卡时 能够在该选项卡上触发 onclick 事件 我确实尝试过这种方式 以及其他几种方式 但没有成功 public void onTabChanged String tabId Log d thi
  • 在 Java 中使用 JSON 的 HTTP POST

    我想在 Java 中使用 JSON 制作一个简单的 HTTP POST 假设网址是www site com 它接受值 name myname age 20 标记为 details 例如 我将如何创建 POST 语法 我似乎也无法在 JSON
  • 背景 x 重复负边距重叠

    实际上是我关于堆栈的第一个问题 我试图在重复背景上获得负 右 边距 这样重复图像之间就不会出现间隙 似乎没有 CSS 语法来实现这一点 为了清楚起见 我在下面添加了一张图片 所以我试图让类似饼干的东西的重复图像重叠 这样它们之间就没有间隙
  • 如果我们在更大的表中使用广播会发生什么?

    我想知道如果我们广播较大的表并将其加入到较小的表中会发生什么 另外 如果我们有两个同样大的表 在这种情况下使用广播连接会发生什么 有几件事需要考虑 火花上限 Spark支持最大8GB的广播表 如果你的广播对象超过这个数量 它就会失败 驱动程
  • 最新的CEDET版本无法加载语义包

    我在加载 Alex Ott 推荐的一些语义包时遇到问题他著名的 CEDET 指南 http alexott net en writings emacs devenv EmacsCedet html使用最新版本的 CEDET 时 我之前的设置
  • 在Python 3中从CGI输出二进制数据

    这个问题与this one https stackoverflow com q 908331 554319 我在从 Python 2 中的 CGI 脚本打印原始二进制数据时没有遇到任何问题 例如 usr bin env python2 im
  • 一元加号和减号运算符的重要用途是什么?

    如果一元 运算符用于执行转换Number 转换函数 那么为什么我们需要一元运算符呢 这些一元运算符有什么特殊需要 一元论 运算符将其操作数转换为 Number 类型 一元论 运算符将其操作数转换为 Number 类型 然后将其取反 根据EC
  • Sublime 代码折叠注释(如 Ace 中)

    在 Cloud9 基于 Ace 编辑器 中 我可以在注释中定义任意代码折叠区域 例如 Descriptor function Code 折叠为 Descriptor lt gt 在这里尝试看看我的意思 http ace c9 io buil
  • ModelClientValidationRule 冲突

    我已将 vs 2011 开发人员预览版与 vs 2010 并排安装 现在 当我在 vs 2010 中运行我的 asp net mvc 3 项目时 我在使用 ModelClientValidationRule 的项目中收到以下错误 Syste
  • 在线代码美化器和格式化程序[关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • 在一个函数中返回两个变量[重复]

    这个问题在这里已经有答案了 考虑以下代码 demo http jsfiddle net m59Fg function test var h Hello var w World return h w var test test alert t
  • Mono 与 CompletableFuture

    CompletableFuture在单独的线程上执行任务 使用线程池 并提供回调函数 假设我有一个 API 调用CompletableFuture 这是 API 调用阻塞吗 线程会被阻塞直到它没有从 API 得到响应吗 我知道主线程 tom
  • 这是从片段中获取字符串资源的正确方法吗?

    在片段中读取字符串资源时 哪种方法通常更好 更安全 我在这里读到getResources getString 直接地 public class SomeFragment extends Fragment public static Some
  • C# - 从客户端检查 TCP/IP 套接字状态

    我想为我的 TCP IP 客户端类提供 CheckConnection 函数 以便我可以检查是否发生了错误 我自己的客户端断开连接 服务器断开连接 服务器卡住等 我有类似的东西 bool isConnectionActive false i
  • 无法在网络视图中滚动图像

    我为 Android 和 iOS 开发了一个 webview 应用程序 我注意到我无法滚动 Android 应用程序中的特定 html 元素 而它可以在 iOS 上运行 这是website https www blizz z de flex