I am making a game in which an imageView
of a ball need to move from one point on the screen to another one. The starting point of the ball is on an imageView
of a hole and I want it to end on another imageView
of a hole.
Anyway, I didn't find any way to get the position of the starting point (the first hole) or the end point (the second hole). I tried to use getLocationOnScreen(Loc)
but it returns 0 all the time.
I really need your help because I am looking for a solution for a long time. If someone can write a detailed answer that would work I will be grateful. Thanks in advance :)
Here is what I tried:
int fromLoc[] = new int[2];
holes[6].getLocationOnScreen(fromLoc);
float startX = fromLoc[0];
float startY = fromLoc[1];
and this:
RelativeLayout.MarginLayoutParams params =
(RelativeLayout.MarginLayoutParams) imgBall0.getLayoutParams();
params.setMargins(holes[5].getLeft(), holes[5].getTop(),
holes[5].getRight(), holes[5].getBottom()); //all in pixels
imgBall0.setLayoutParams(params);
holes[5]
is the ending point to which the imgBall0
needs to arrive.
holes[5]
is an imageButton
which is in a relativeLayout
and in a LinearLayout
.
Thanks again!