我已经使用 Canvas View 方法绘制了饼图,但现在我想要点击单个饼图?我怎样才能做到这一点?
最佳答案
我得到了这个问题的完美答案:
获取点击区域的颜色代码,并检查颜色是否与您的颜色代码匹配,这将获得您想要的点击。
@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);
}
关于android - 如何获得 Canvas 区域点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17469915/