Get the Y coordinate of the top and bottom of ImageView

I have a representation of an image that is contained in a relative layout. I am trying to get the screen y coordinates of the top of the image and the coordinates of the screen y at the bottom of the image. I tried this:

float yMin = (float)levelH.getTop(); float yMax = (float)levelH.getBottom(); 

float yMin seems almost correct. I translate another image (IM2) up and down this image (IM1). So I am trying to set a limit on how far (IM2) can be moved up and down. So I was thinking about getting y top and bottom (IM1), I can set them as max and min.

Does anyone know how to do this?

ps Im using Android accelerator to move (IM2)

+4
source share
2 answers

getTop() ansd getBottom() Look at the coordinates inside it parent. To get the coordinates of its position on the screen, you can use getLocationOnScreen

Use it as follows:

 int[] coords = {0,0}; view.getLocationOnScreen(coords); int absoluteTop = coords[1]; int absoluteBottom = coords[1] + view.getHeight(); 
+13
source

Use View.getLocationOnScreen () and / or getLocationInWindow ()

0
source

Source: https://habr.com/ru/post/1501858/


All Articles