如何获得一个圆形的Imageview中心

Dev*_*ith 2 android touch-event android-imageview

现在我有一个ImgeView,它有一个圆圈,我想找到那个圆圈的中心点,所以我尝试了下面的代码,但似乎没有工作

int[] location = new int[2];
            imageView.getLocationOnScreen(location);

int radius=imageView.getHeight()/2;
                    int[] center=new int[2];
                    center[0]=location[0]+radius;
                    center[1]=location[1]+radius;
Run Code Online (Sandbox Code Playgroud)

所以我通过"位置"得到的坐标是图像视图的顶点还是没有?

请帮我看看如何获​​得imageview的中心点.

Cha*_*iga 10

我假设下面的情况:

您将加载一个ImageView(来自xml或代码)并在myImageView(例如)中引用它.现在,您希望计算myImageView的中心,而不管它在屏幕上的位置.

如果我的假设是正确的,那么下面可能是您正在寻找的解决方案:

    int centerXOnImage=myImageView.getWidth()/2;
    int centerYOnImage=myImageView.getHeight()/2;

    int centerXOfImageOnScreen=myImageView.getLeft()+centerXOnImage;
    int centerYOfImageOnScreen=myImageView.getTop()+centerYOnImage;
Run Code Online (Sandbox Code Playgroud)