2013-07-04 92 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坐标,从而确定其中的馅饼片点击是