2013-02-19 58 views

回答

0

一個好辦法做到這一點是使用OnTouchListener代替OnClickListener

這裏是一個示例代碼:

ImageView myView = (ImageView) findViewById(R.id.image_view); 
    myView.setOnTouchListener(new OnTouchListener(){ 

     @Override 
     public boolean onTouch(View view, MotionEvent event) { 
      // TODO Auto-generated method stub 
      if (event.getAction() == MotionEvent.ACTION_DOWN) { 
       float x = event.getX(); 
       float y = event.getY(); 
       float xRef = view.getX(); 
       float yRef = view.getY(); 
       // calcualte position inside view 
       x = x - xRef; 
       y = y - yRef; 
       //decode (x, y) to parts 

       return true; 
      } 
      return false; 
     } 

    }); 
+0

我不明白..我怎樣才能使用這個? – darkmax 2013-02-25 13:42:08