"Android" to the gallery inside " controls " Mount events, swipe to lift the finger when the event is also triggered (should not be triggered when sliding) to resolve,!

Source: Internet
Author: User
Tags xdiff

Ideas:

1.gallery Internal Control mount events (such as: Onclicklistener) are similar to the ListView, which can be mounted directly within the Baseadapter.getview (detailed method Baidu).

2. It seems to be no problem, but it is not true that the event is triggered when you lift your finger after sliding (finger on the control that mounts the event).

Workaround, if you are sliding (x has an offset), the event is intercepted in Gallery.onintercepttouchevent, and the child control naturally accepts no events.

Note:1> can not simply infer that X has an offset to intercept, some devices are cheap, even if the position is raised there may be offset, this should trigger the onclick is also intercepted.

Therefore, to be compatible with most machines, you need to move horizontally beyond a certain threshold to intercept.

So within the threshold range, the gallery is not moving.

3. The problem comes again, when you slowly slide the 2nd item, you will find that the "child" has a distinct mutation (x-coordinate mutation).

The basic reason is that the gallery starts to move normally when it appears that the sliding exceeds the threshold, and in fact the gallery also does some initialization when the hand starts moving (gallery is not yet moved), causing an error when the gallery really moves.

Workaround, when you swipe your finger within the threshold, you keep doing this initialization so that when the gallery really starts moving, there is no error in initialization.


public class Mygallery extends Gallery {float Mlastmotionx = 0;public mygallery (context context) {super (context);//TODO A Uto-generated Constructor Stub}public Mygallery (context context, AttributeSet attrs, int defstyle) {Super (context, attrs , defstyle);//TODO auto-generated Constructor Stub}public mygallery (context context, AttributeSet Attrs) {Super (context , attrs);//TODO auto-generated constructor stub} @Overridepublic boolean onintercepttouchevent (motionevent ev) {final int action = Ev.getaction (); final float x = ev.getx (); switch (action) {case MotionEvent.ACTION_MOVE:final int xdiff = (int ) Math.Abs (X-mlastmotionx); if (Xdiff >50) {return true;} Break;case MotionEvent.ACTION_DOWN:mLastMotionX = x;//A mutation ontouchevent (EV) occurs when the "2nd item" is prevented from sliding; return false;}}


"Android" to the gallery inside " controls " Mount events, swipe to lift the finger when the event is also triggered (should not be triggered when sliding) to resolve,!

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.