Search code examples
androidfresco

Fresco ZoomableDraweeView set onClickListenet


I am developing an app which has a gallery view using Fresco library. I have a requirement where the user can zoom the image. So I have used ZoomableDraweeView which is available in Fresco sample projects. Displaying the images and zooming them works perfectly, however I also need to set an onClicklistener for the ZoomableDraweeView. I have tried setting the default clickListener which is used in Android, but it isn't getting clicked. Below is the code I have used to set the clicklistener

ZoomableDraweeView view = new ZoomableDraweeView(container.getContext());
                    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(images.get(position).getFull_url()))
                            .setProgressiveRenderingEnabled(true)
                            .build();
                    view.setController(
                            Fresco.newDraweeControllerBuilder().setLowResImageRequest(ImageRequest.fromUri(images.get(position)
                                    .getThumb_url()))
                                    .setImageRequest(request).setOldController(view.getController())
                                    .build());
                    GenericDraweeHierarchy hierarchy =
                            new GenericDraweeHierarchyBuilder(container.getResources())
                                    .setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)
                                    .setProgressBarImage(null)
                                    .build();
                    view.setHierarchy(hierarchy);
                    ((ViewPager) container).addView(view, 0);
      view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //Toast..... I need this to be called
                }
            });
                    return view;

Thanks in advance. https://github.com/facebook/fresco/tree/master/samples/zoomable/src/main/java/com/facebook/samples/zoomable


Solution

  • The default touch behaviors was override in ZoomableDraweeView, onClick cannot trigger now. I've tried setTapListener and it works.

    zoomableDraweeView.setTapListener(new DoubleTapGestureListener(finalZoomableDraweeView){
                    @Override
                    public boolean onSingleTapConfirmed(MotionEvent e) {
                        if(mItemClickListener != null){
                            mItemClickListener.onClick(finalZoomableDraweeView);
                        }
                        return super.onSingleTapConfirmed(e);
                    }
                });
    

    To get more infomation, please refer to my demo: https://github.com/ibosong/CommentGallery