Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8577201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:06:24+00:00 2026-06-11T20:06:24+00:00

i’m developing a simple android application with a RelativeLayout and a WebView inside. I

  • 0

i’m developing a simple android application with a RelativeLayout and a WebView inside.

I have to detect swipe from bottom to top done only in the 20% of the left part of the screen. So when user swipe in that space from bottom to top i have to show a custom dialog.

What i try is:

import android.app.Activity;
import android.view.MotionEvent;
import android.view.View;

public class ActivitySwipeDetector implements View.OnTouchListener {

    static final String logTag = "ActivitySwipeDetector";
    private Activity activity;
    static final int MIN_DISTANCE = 100;
    private float downY, upY;

    public ActivitySwipeDetector(Activity activity){
        this.activity = activity;
    }

    public void onRightToLeftSwipe(){

    }

    public void onLeftToRightSwipe(){

    }

    public void onTopToBottomSwipe(){

    }

    public void onBottomToTopSwipe(){
        System.out.println("BOTTOM TO TOP SWIPE DONE!");
    }

    public boolean onTouch(View v, MotionEvent event) {
        switch(event.getAction()){
        case MotionEvent.ACTION_DOWN: {
            downY = event.getY();
            return true;
        }
        case MotionEvent.ACTION_UP: {
            upY = event.getY();
            float deltaY = downY - upY;
            if(Math.abs(deltaY) > MIN_DISTANCE){
                if(deltaY > 0) { this.onBottomToTopSwipe(); return true; }
            }
            else {
                return false;
            }

            return true;
        }
        }
        return false;
    }

}

    layout = (RelativeLayout)this.findViewById(R.id.layout);
    layout.setOnTouchListener(activitySwipeDetector);

But it doesn’t do nothing!

So i try creating a custom webview in this way:

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.webkit.WebView;

public class MyWebView extends WebView {
    public MyWebView(Context context) {
        super(context);
    }
    public MyWebView(Context context,AttributeSet set){
        super(context,set);
    }



    @Override 
    public boolean onTouchEvent(MotionEvent evt) {   

        boolean consumed = super.onTouchEvent(evt); 
        if (isClickable()) { 
            switch (evt.getAction()) { 
            case MotionEvent.ACTION_DOWN:  
                lastTouchY = evt.getY();
                downTime = evt.getEventTime();
                hasMoved = false; 
                break; 
            case MotionEvent.ACTION_MOVE: 
                hasMoved = moved(evt); 
                break; 
            case MotionEvent.ACTION_UP: 
                float actualTouchY = evt.getY();
                long currentTime = evt.getEventTime();
                float difference = Math.abs(lastTouchY - actualTouchY);
                long time = currentTime - downTime;

                if ( (lastTouchY < actualTouchY) && (time < 220) && (difference > 100) ) {
                    System.out.println("SWIPE1");
                }
                if ( (lastTouchY > actualTouchY) && (time < 220) && (difference > 100) ) {
                    System.out.println("SWIPE2");
                }
                break; 
            } 
        } 
        return consumed || isClickable(); 
    } 
    long downTime;
    private float lastTouchY; 
    private boolean hasMoved = false; 
    private boolean moved(MotionEvent evt) { 
        return hasMoved || 
                Math.abs(evt.getY() - lastTouchY) > 10.0; 
    }

}

but with no success!!! can someone help me?? THAnks!!!!! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:06:26+00:00Added an answer on June 11, 2026 at 8:06 pm

    Use a GestureDetector with a custom web view..

    webView.setGestureDetector(new GestureDetector(new CustomeGestureDetector()));   
    

    the gesture detector:

    private class CustomeGestureDetector extends SimpleOnGestureListener {      
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            if(e1 == null || e2 == null) return false;
            if(e1.getPointerCount() > 1 || e2.getPointerCount() > 1) return false;
            else {
                try { // right to left swipe .. go to next page
                    if(e1.getX() - e2.getX() > 100 && Math.abs(velocityX) > 800) {
                        //do your stuff
                        return true;
                    } //left to right swipe .. go to prev page
                    else if (e2.getX() - e1.getX() > 100 && Math.abs(velocityX) > 800) {
                        //do your stuff
                        return true;
                    } //bottom to top, go to next document
                    else if(e1.getY() - e2.getY() > 100 && Math.abs(velocityY) > 800 
                            && webView.getScrollY() >= webView.getScale() * (webView.getContentHeight() - webView.getHeight())) {
                        //do your stuff
                        return true;
                    } //top to bottom, go to prev document
                    else if (e2.getY() - e1.getY() > 100 && Math.abs(velocityY) > 800 ) {
                        //do your stuff
                        return true;
                    } 
                } catch (Exception e) { // nothing
                }
                return false;
            }
        }
    }
    

    The custom web view:

    public final class CustomWebView extends WebView {
    
    private GestureDetector gestureDetector;
    
    /**
     * @param context
     * @param attrs
     * @param defStyle
     */
    public CustomWebView(Context context) {
        super(context);
    }
    
    /**
     * @param context
     * @param attrs
     * @param defStyle
     */
    public CustomWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    
    /**
     * @param context
     * @param attrs
     * @param defStyle
     */
    public CustomWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    
    /* 
     * @see android.webkit.WebView#onScrollChanged(int, int, int, int)
     */
    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
    }
    
    /* 
     * @see android.webkit.WebView#onTouchEvent(android.view.MotionEvent)
     */
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return gestureDetector.onTouchEvent(ev) || super.onTouchEvent(ev);
    }
    
    public void setGestureDetector(GestureDetector gestureDetector) {
        this.gestureDetector = gestureDetector;
    }
    }
    

    As said by Андрей Москвичёв:

    It can be solved without deriving WebView class, by registering touch listener: webview.setOnTouchListener(new OnTouchListener() ...) and calling gestureDetector.onTouchEvent(ev) from it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.