图片打标签之获取图片在ImageView中的坐标

android matrix 最全方法详解与进阶(完整篇)

imageView = findViewById(R.id.imageview);
        
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Drawable drawable = imageView.getDrawable();
                Matrix matrix = imageView.getImageMatrix();
                if (drawable != null) {
                    RectF rectf = new RectF();
                    rectf.set(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
                    matrix.mapRect(rectf);     //最关键的一句
                    Log.i("lcf", "left  " + rectf.left + "  " + rectf.top + "  " + rectf.right + "  " + rectf.bottom);

                }
            }

你可能感兴趣的:(android)