ScrollView and Gallery interfering

前端 未结 5 1169
我在风中等你
我在风中等你 2020-12-16 06:44

I have a Gallery composed of many ScrollViews each of which occupies the whole screen. problem is the ScrollViews\' onTouchEvent returns true and therefore prevent any other

5条回答
  •  借酒劲吻你
    2020-12-16 07:21

    How about this solution: Simply handle the event in both, the ScrollView and the Gallery:

    public class GalleryFriendlyScrollView extends ScrollView {
        private Gallery fParent;
    
    
        public GalleryFriendlyScrollView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
    
        @Override
        public boolean onTouchEvent(MotionEvent ev) {
            boolean superDone = super.onTouchEvent(ev);
            // correct the location of the event because the gallery
            // might have moved the scroll pane horizontally
            ev.setLocation(ev.getX() + getLeft(), ev.getY());
            // dispatch the event also to the gallery
            boolean galleryDone = getGallery().onTouchEvent(ev);
            return superDone || galleryDone;
        }
    
        private Gallery getGallery() {
            if (fParent == null) {
                fParent = (Gallery)this.getParent();
            }
            return fParent;
        }
    }
    

提交回复
热议问题