如何在使用自定义ImageView的活动中实现OnTouchListener



我有一个自定义的ImageView,我的活动之一(例如 Activity a)使用了自定义的ImageView。我喜欢在Activity A中实现该自定义视图的onTouchListener。我只是实现onTouchListener作为正常ImageView实现。但这行不起作用。

   DrawView m_view = null;
   protected void onCreate(Bundle savedInstanceState) {
   m_view = (DrawView) findViewById(R.id.textextraction_manipulation);  
   m_view .setOnTouchListener(new OnTouchListener() {            
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return false;
        }
    });
}

为什么它不起作用?谢谢

尝试实现这样的东西,

 m_view .setOnTouchListener(new OnTouchListener() {            
        @Override
        public boolean onTouch(View v, MotionEvent event) {
           switch(event.getAction & MotionEvent.ACTION_MASK)
           {
              case MotionEvent.ACTION_DOWN : //Do your stuff here
                                            break;
              case MotionEvent.ACTION_UP:  //To do
                                         break;
            }
            return true;;
        }
    });

最新更新