1

I'm making a app for Android that shows a camera image (after going through some manipulation) on screen using an ImageView and I want to allow to move other ImageViews on the screen - but only inside the the parent ImageView.

Also, I need to get the coordinates of the child views relative to the coordinates of the parent ImageView. i.e - So that (0,0) will not be the whole screen, but the ImageView that shows the camera.

Is that possible at all? If so - How?

Help is much appreciated! Thanks

Roman
  • 4,443
  • 14
  • 56
  • 81

1 Answers1

1

If you want to move the views by drag here's a lot of info around, e.g Moving image with touch events .

What about getting the top and left side of minorView relative to majorView it's also straightforward with some plain substraction minorViewRelativeTop = minorViewTop - majorViewTop. Use View.getLocationInWindow() for getting these absolute positions.

N.B. That View.getLocationInWindow() will usually not work just inside Activity.onCreate() so better call it after some delay. For testing it could be sth like:

majorView.postDelayed(new Runnable() {
            @Override
            public void run() {
                int[] location = new int[2];
                majorView.getLocationInWindow(location);
                int majorViewLeft = location[0];
                int majorViewTop = location[1];
            }
        }, 1000);
Community
  • 1
  • 1
riwnodennyk
  • 8,140
  • 4
  • 35
  • 37