Android detects right-sliding WebView and androidwebview

Source: Internet
Author: User

Android detects right-sliding WebView and androidwebview

Today, the new product has to slide right .... After the right-sliding gesture is detected, the event is not processed and placed in the Activity for corresponding processing.

Import android. app. activity; import android. content. context; import android. util. attributeSet; import android. view. motionEvent; import android. view. velocityTracker; import android. view. view; import android. view. view. onTouchListener; import android. webkit. webSettings; import android. webkit. webSettings. renderPriority; import android. webkit. webView; public class MyWebView extends WebView {// minimum speed privat when the finger slides to the right E static final int XSPEED_MIN = 200; // The minimum private static final int XDISTANCE_MIN = 150 when the finger slides to the right; // record the abscissa when the finger is pressed. Private float xDown; // records the abscissa when the finger moves. Private float xMove; // used to calculate the speed at which the finger slides. Private VelocityTracker mVelocityTracker; Context mContext; public MyWebView (Context context) {super (context); this. mContext = context; init ();} public MyWebView (Context context, AttributeSet attrs) {super (context, attrs); this. mContext = context; init ();} public MyWebView (Context context, AttributeSet attrs, int defStyle) {super (context, attrs, defStyle); this. mContext = context; init ();} private void init () {SetScrollBarStyle (0); // set the width of the scroll bar WebSettings webSettings = getSettings (); webSettings. setJavaScriptEnabled (true); webSettings. setSaveFormData (false); webSettings. setSavePassword (false); webSettings. setsuppzoom zoom (false); webSettings. setGeolocationEnabled (true); webSettings. setRenderPriority (RenderPriority. HIGH); webSettings. setSupportMultipleWindows (true); webSettings. setLoadsImagesAutomatically (true ); WebSettings. setUseWideViewPort (true) ;}@ Override public boolean onTouchEvent (MotionEvent event) {createVelocityTracker (event); switch (event. getAction () {case MotionEvent. ACTION_DOWN: xDown = event. getRawX (); break; case MotionEvent. ACTION_MOVE: xMove = event. getRawX (); // The distance from the activity to int distanceX = (int) (xMove-xDown); // you can call this operation to obtain the int xSpeed = getScrollVelocity (); // when the sliding distance is greater than the minimum distance we set and the instantaneous sliding speed is greater than the preset speed, Return to the previous activity // if (distanceX> XDISTANCE_MIN & xSpeed> XSPEED_MIN) {if (distanceX> XDISTANCE_MIN) {return false;} break; case MotionEvent. ACTION_UP: recycleVelocityTracker (); break; default: break;} return super. onTouchEvent (event);}/*** creates a VelocityTracker object, and adds a sliding event that touches the content interface to VelocityTracker. ** @ Param event **/private void createVelocityTracker (MotionEvent event) {if (mVelocityTracker = null) {mVelocityTracker = VelocityTracker. obtain ();} mVelocityTracker. addMovement (event);}/*** recycles the VelocityTracker object. */Private void recycleVelocityTracker () {mVelocityTracker. recycle (); mVelocityTracker = null;}/*** get the speed at which the finger slides on the content interface. ** @ Return sliding speed, measured in the unit of how many pixels are moved per second. */Private int getScrollVelocity () {mVelocityTracker. computeCurrentVelocity (1000); int velocity = (int) mVelocityTracker. getXVelocity (); return Math. abs (velocity );}}



How does android disable webview sliding between the left and right sides?

Add android: scrollbars = "vertical" to the xml webview attribute"

How can we solve the problem of android Sliding Screen webview sliding conflict? Please, 3Q.

Customize a control to inherit webview, override the onScroll method, and add your own processing. View Original post>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.