Slide conflict between the Android slide menu and the slideshow image, android slide

Source: Internet
Author: User

Slide conflict between the Android slide menu and the slideshow image, android slide

To take over a project, you must modify the following question: a slideshow image cannot be moved manually. A manual slideshow image can only trigger a slide menu.

 

Guess: the touch event of the viewpager control is intercepted by the SlidingMenu control (a slide menu, not a third-party project, but customized by the previous Developer.

 

Based on this guess, I customize a ViewPager, rewrite dispatchTouchEvent, onInterceptTouchEvent, and onTouchEvent, and print logs in these three methods respectively;

Override the dispatchTouchEvent, onInterceptTouchEvent, and onTouchEvent of SlidingMenu, and print the log.

 

Re-compile and run the task:

06-08 09:52:08.394 19424-19424/com.parkingmore E/SlidingMenu: dispatchTouchEvent ev:006-08 09:52:08.395 19424-19424/com.parkingmore E/SlidingMenu: onInterceptTouchEvent ev:006-08 09:52:08.395 19424-19424/com.parkingmore E/RollViewPager: dispatchTouchEvent ev:006-08 09:52:08.395 19424-19424/com.parkingmore E/RollViewPager: onInterceptTouchEvent ev:006-08 09:52:08.441 19424-19424/com.parkingmore E/SlidingMenu: dispatchTouchEvent ev:206-08 09:52:08.441 19424-19424/com.parkingmore E/SlidingMenu: onInterceptTouchEvent ev:206-08 09:52:08.442 19424-19424/com.parkingmore E/SlidingMenu: ACTION_MOVE dx:15.47399906-08 09:52:08.442 19424-19424/com.parkingmore E/RollViewPager: ACTION_MOVE getCurrentItem():106-08 09:52:08.442 19424-19424/com.parkingmore E/RollViewPager: dispatchTouchEvent ev:206-08 09:52:08.442 19424-19424/com.parkingmore E/RollViewPager: onInterceptTouchEvent ev:206-08 09:52:08.459 19424-19424/com.parkingmore E/SlidingMenu: dispatchTouchEvent ev:206-08 09:52:08.459 19424-19424/com.parkingmore E/SlidingMenu: onInterceptTouchEvent ev:206-08 09:52:08.459 19424-19424/com.parkingmore E/RollViewPager: dispatchTouchEvent ev:306-08 09:52:08.459 19424-19424/com.parkingmore E/RollViewPager: onInterceptTouchEvent ev:306-08 09:52:08.477 19424-19424/com.parkingmore E/SlidingMenu: dispatchTouchEvent ev:206-08 09:52:08.477 19424-19424/com.parkingmore E/SlidingMenu: onTouchEvent ev:206-08 09:52:08.495 19424-19424/com.parkingmore E/SlidingMenu: dispatchTouchEvent ev:206-08 09:52:08.495 19424-19424/com.parkingmore E/SlidingMenu: onTouchEvent ev:206-08 09:52:08.515 19424-19424/com.parkingmore E/SlidingMenu: dispatchTouchEvent ev:206-08 09:52:08.515 19424-19424/com.parkingmore E/SlidingMenu: onTouchEvent ev:206-08 09:52:08.533 19424-19424/com.parkingmore E/SlidingMenu: dispatchTouchEvent ev:206-08 09:52:08.533 19424-19424/com.parkingmore E/SlidingMenu: onTouchEvent ev:206-08 09:52:08.551 19424-19424/com.parkingmore E/SlidingMenu: dispatchTouchEvent ev:206-08 09:52:08.551 19424-19424/com.parkingmore E/SlidingMenu: onTouchEvent ev:206-08 09:52:08.574 19424-19424/com.parkingmore E/SlidingMenu: dispatchTouchEvent ev:206-08 09:52:08.574 19424-19424/com.parkingmore E/SlidingMenu: onTouchEvent ev:206-08 09:52:08.594 19424-19424/com.parkingmore E/SlidingMenu: dispatchTouchEvent ev:206-08 09:52:08.595 19424-19424/com.parkingmore E/SlidingMenu: onTouchEvent ev:206-08 09:52:08.611 19424-19424/com.parkingmore E/SlidingMenu: dispatchTouchEvent ev:206-08 09:52:08.612 19424-19424/com.parkingmore E/SlidingMenu: onTouchEvent ev:206-08 09:52:08.622 19424-19424/com.parkingmore E/SlidingMenu: dispatchTouchEvent ev:206-08 09:52:08.622 19424-19424/com.parkingmore E/SlidingMenu: onTouchEvent ev:206-08 09:52:08.623 19424-19424/com.parkingmore E/SlidingMenu: dispatchTouchEvent ev:1
View Code

It can be seen from the log that the sliding event can be passed to ViewPager at the beginning, and then it will be intercepted by SlidingMenu. This log confirms that this conjecture is correct.

 

If you know the reason, you can solve the problem. Now, I want to consider the effect to be achieved.

 

Expected effect: you can slide the slideshow image normally. When the slideshow is in the first one, you can slide to the slide menu.

 

Some people share similar issues on the Internet. I will also learn from it here.

 

First, implement the first function: you can slide the carousel image normally.

 

You can set a global variable: public static boolean mRollViewPagerTouching;

Used to indicate whether or not the image is being played by a touch.

 

In custom ViewPager, determine whether or not to touch the carousel Image

public boolean dispatchTouchEvent(MotionEvent ev) {        switch (ev.getAction()) {            case MotionEvent.ACTION_MOVE:                break;            case MotionEvent.ACTION_DOWN:                MyApplication.mRollViewPagerTouching = true;                break;            case MotionEvent.ACTION_UP:                MyApplication.mRollViewPagerTouching = false;                break;        }        return super.dispatchTouchEvent(ev);    }
View Code

In SlidingMenu, perform the following processing:

public boolean onInterceptTouchEvent(MotionEvent ev) {        if (MyApplication.mRollViewPagerTouching){            return false;        }        return super.onInterceptTouchEvent(ev);    }
View Code

 

Re-compile and run the task. You can slide the slideshow image normally. However, when the slideshow is the first one, it cannot slide to the slide menu.

 

Now let's do the second function: When the carousel image is in the first one, you can slide to the slide menu.

There are two points to note: 1. when the carousel image is in the first image; 2. because my slide menu is on the left, you need to slide your fingers to the right to enter the slide menu, so the second condition should be right slide.

On the basis of the above, modify the custom ViewPager code

Public boolean dispatchTouchEvent (MotionEvent ev) {// go back to the starting coordinate float x = ev at the time of triggering. getX (); switch (ev. getAction () {case MotionEvent. ACTION_MOVE: // get the Distance Difference float dx = x-downX; // prevent the if (Math. abs (dx)> 8) {// determine the direction using the Distance Difference if (dx> 0) {// "right"; if (getCurrentItem () = 0) {MyApplication. mRollViewPagerTouching = false;} else {MyApplication. mRollViewPagerTouching = true ;}} else {// "Left"; MyApplication. mRollViewPagerTouching = true ;}} break; case MotionEvent. ACTION_DOWN: // store downX = x; MyApplication. mRollViewPagerTouching = true; break; case MotionEvent. ACTION_UP: MyApplication. mRollViewPagerTouching = false; break;} return super. dispatchTouchEvent (ev );}
View Code

 

Compile and run again to achieve the expected results.

 

Ps: simple functions and simple sharing.

 

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.