"Android" to the gallery inside the "control" mount event, sliding and lifting the finger when the event (should not be triggered when sliding) to resolve,!

Source: Internet
Author: User

Ideas:

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

2. It doesn't seem to be a problem, but it is not right to trigger the event when you lift your finger after sliding (the finger is on the control that is mounting 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 determine the x has an offset to intercept, some equipment to make a base, 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 seemingly sliding beyond the threshold, the gallery began to move normally, in fact, when the hand began to move (Gallery has not moved), gallery also did some initialization, resulting in gallery real movement error.

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


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.