android - how to get the image edge x/y position inside imageview

前端 未结 4 840
不知归路
不知归路 2020-12-23 15:01

If i have an ImageView that fills the screen.
The ImageView background is set to green color.
I place a bitmap in the ImageView, keeping bitmap proportions.

4条回答
  •  鱼传尺愫
    2020-12-23 15:30

    You should be able to get the (x, y) coordinates of the drawable inside, if that's what you're looking for. Try this:

    ImageView img = (ImageView)findViewById(R.id.img);
    Rect r = img.getDrawable().getBounds();
    
    int drawLeft = r.left;
    int drawTop = r.top;
    int drawRight = r.right;
    int drawBottom = r.bottom;
    

    drawLeft is your X value.

    drawTop is your Y value.

提交回复
热议问题