您好,我正在创建塔布拉应用程序,
例如
它不应该在圆形之外响应,但 ImageView 是矩形,所以它正在响应
我相信你能理解这个问题
ImageView 是矩形,但它的图像是圆形的,但我只想检测对圆形图像的点击...
最佳答案
感谢您的所有支持,基于您的支持,我已经通过以下方式完成并且工作完美
ImageView imgView = (ImageView) findViewById(R.id.imageView1);
imgView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//CIRCLE : (x-a)^2 + (y-b)^2 = r^2
float centerX, centerY, touchX, touchY, radius;
centerX = v.getWidth() / 2;
centerY = v.getHeight() / 2;
touchX = event.getX();
touchY = event.getY();
radius = centerX;
System.out.println("centerX = "+centerX+", centerY = "+centerY);
System.out.println("touchX = "+touchX+", touchY = "+touchY);
System.out.println("radius = "+radius);
if (Math.pow(touchX - centerX, 2)
+ Math.pow(touchY - centerY, 2) < Math.pow(radius, 2)) {
System.out.println("Inside Circle");
return false;
} else {
System.out.println("Outside Circle");
return true;
}
}
});
关于android - 创建圆形的 ImageView,因此点击仅适用于圆形区域 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28090386/