With an activity extending view, in the bottom of the layout, there is a going-left and going-right button at the left and right bottom corner of the screen.
There is an boy imagebutton in the middle of the screen.
I would like to implement in a way that when the user presses the left button, the boy imagebutton button will move to the left (limited to the left of the screen), so as the action for the right button: the boy will move to the right.
I would like to know how the above can be achieved?
I have tried the following in a hope to get the coordinates of the boy at first step
public void get_boy_location()
{
Rect rectf = new Rect();
image_boy.getLocalVisibleRect(rectf);
textView_testing.setText(
"\n WIDTH:" + String.valueOf(rectf.width()) +
"\n HEIGHT:" + String.valueOf(rectf.height()) +
"\n left:" + String.valueOf(rectf.left) +
"\n right:" + String.valueOf(rectf.right) +
"\n top:" + String.valueOf(rectf.top) +
"\n bottom:" + String.valueOf(rectf.bottom)
);
}
but all the values report 0.
Question: 1. How could we implement a controlling left and right button to move the boy imagebutton horizontally?
- How to obtain the coordinates of the imagebutton?
Thanks!!