Disable OnClickListener while scaling or dragging a View

感情迁移 提交于 2019-12-11 09:42:56

问题


Hi I'm using MPAndroidChart and my added OnClickListener is triggered right after i zoomed into or dragged a chart. How can i disable this behavior?

This are my chart properties:

chart.setTouchEnabled(true);        
chart.setScaleEnabled(true);
chart.setDragEnabled(true);        
chart.setPinchZoom(true);
chart.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
        //this only should run if i really click on the chart, not if i zoom or drag it.
        ...     
    });

Is there an easy way to do it? This ClickListener, ScaleListener and ScaleGestureDetector gang bang ist kinda complicated :/

thanks in advance


回答1:


Implement the ScaleGestureDetector in http://android-developers.blogspot.com.tr/2010/06/making-sense-of-multitouch.html . At onScale Event, remove the OnClickListener with chart.setOnClickListener(null). Then Implement an OnTouchListener and add onClickListener at ACTION_UP.

This should allow you to avoid triggering onClick events at pinch to zoom.



来源:https://stackoverflow.com/questions/31257322/disable-onclicklistener-while-scaling-or-dragging-a-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!