创建圆形的ImageView,因此单击仅适用于圆形区域的android [英] Create ImageView that is round, so click will work on round area only android

查看:53
本文介绍了创建圆形的ImageView,因此单击仅适用于圆形区域的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建tabla应用,

Hi I am creating tabla App,

例如

它不应该在圆形之外响应,但是ImageView是Rectangle以便响应.

我确定您可以理解这个问题

I am sure you can understand this problem

ImageView是矩形,但是它的图像是圆形的,但是我只想检测单击圆形图像...

ImageView is rectangle but it's image is round, but I want to detect click only on round image...

推荐答案

感谢您的全力支持,基于您对我的支持,我已经通过下面的方式提供了帮助,

Thank you for your all support, based on your support I have done by below way and it is working perfect

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;
                }
            }
        });

这篇关于创建圆形的ImageView,因此单击仅适用于圆形区域的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆