2013-07-04 98 views

回答

3

我得到了這個問題完美的答案:點擊區域的

獲得色彩代碼,如果色彩搭配與顏色C檢頌讚這將得到點擊你想要的。

@Override 
public boolean onTouchEvent(MotionEvent event) { 

    float touchX = event.getX(); 

    float touchY = event.getY(); 

    Logger.debug("X-->"+touchX+" Y---->"+touchY); 

    //get drawing cache of your view 
    Bitmap bitmap = getDrawingCache(true); 

      //Get color code of pixle where you have tap 
    int colorCode=bitmap.getPixel((int)touchX,(int)touchY); 

    if(colorCode == context.getResources().getColor(R.color.pie_blue)) { 
     Logger.debug("Color blue"); 
     onPieClick.onBluePieClick(touchX,touchY); 
    }else if(colorCode == context.getResources().getColor(R.color.pie_green)) { 
     Logger.debug("Color green"); 
     onPieClick.onGreenPieClick(touchX,touchY); 
    } 

    return super.onTouchEvent(event); 


} 
0

你可以做的是,

  • 覆蓋onTouch事件&你會得到運動事件,

  • 您將得到event.getX點擊的X & y座標( )分別爲& event.getY()。

  • 確定這個x & y在餅圖中相交。

示例代碼:

1)簡單

public boolean onTouchEvent(MotionEvent event) { 
     if(event.getAction()==MotionEvent.ACTION_UP){ 
     float xCord=event.getX(); 
     float yCord = event.getY(); 
     .... 
     Write condition to identify where this x & y intersect in pie. 
     ... 
    } 
    return true; 
} 

2)另一種方式獲得的觸摸(好辦法)

OnGestureListener mGestureListener=new GestureDetector.SimpleOnGestureListener(){ 
     public boolean onSingleTapConfirmed(MotionEvent e) { 
      float xCord=e.getX(); 
      float yCord = e.getY(); 
      .... 
      identify where this x & y intersect in pie. 
      ... 
     }; 
    }; 
GestureDetector gestureDetector=new GestureDetector(context, mGestureListener); 
public boolean onTouchEvent(MotionEvent event) { 
      gestureDetector.onTouchEvent(event); 
     return true; 
    } 
0

你不能。那麼,至少不是直接。

你可以做,雖然以下幾點:

  1. 在該視圖的單擊處理程序,確定點擊
  2. 比較你寫的繪製代碼的XY座標,從而確定其中的餡餅片點擊是