How to get Coordinates on touch Event on bitmap not of Screen

后端 未结 2 1515
误落风尘
误落风尘 2020-12-18 13:31

Greets ,

How can I get the Coordinates of the Bitmap not of the screen. Screen Coordinates got by event.getX(),event.getY() methods but not getting coordinates of th

2条回答
  •  别那么骄傲
    2020-12-18 13:45

    You can't get the coordinates of the bitmap directly. You need to calculate to yourself. Use the position of the ImageView, and with that you can handle it.

    Of course, when you are after Activity onCreate you can acces to any inflated (active) views parameter. Exemple. ImageView a; a.getPaddingBottom(); Like all coordinats (left right etc...) After this you need the Height and Width of the ImageView. Nah, when you know the views position, hegiht and width you can calculate.

    Example:

    final ImageView iv_YourImage = (ImageView) findViewById(R.id.iv_imageview);
    public boolean onTouch(View v, MotionEvent event){
    int topParam =  iv_YourImage.getPaddingTop();
     int rightParam =  iv_YourImage.getPaddingRight();
    int maxTopParam = topParam+iv_YourImage.getMaxHeight();
    int maxRightParam = rightParam + iv_YourImage.getMaxWidth();
     if(event.getX>topParam&&event.getX

提交回复
热议问题