Garmaine Staff asked 1 year ago

I am trying to put an ImageView between 2 moving ball objects. Using a path drawer is not possible since I try to avoid the OnDraw method because of its limitations(60 refreshes/second). The 2 ball objects are continuously moving on the screen (but always with the same distance from each other). Since the x and y coordinates are always changing, it would be nice to set the endpoints of the 'stick' object to the 2 positions where the 2 balls are standing in that specific scenario, and of course, when they have moved, reset the stick between the new endpoints.

protected void onCreate(Bundle savedInstanceState) {

    ball = (ImageView) findViewById(;
    ball2 = (ImageView) findViewById( ;

    widthMiddle = getWindowManager().getDefaultDisplay().getWidth() / 2;
    heightMiddle = getWindowManager().getDefaultDisplay().getHeight() / 2;

    timer.schedule(new TimerTask() {
        public void run() {
   Runnable() {
                public void run() {
                    x1 = widthMiddle + r1 * (float)Math.sin(Math.toRadians(a1));
                    y1 = heightMiddle + r1 * (float)Math.cos(Math.toRadians(a1));
                    x2 = x1 + r2 * (float)Math.sin(Math.toRadians(a2));
                    y2 = y1 + r2 * (float)Math.cos(Math.toRadians(a2));
                    a1 += 1.0;
                    a2 -= 2.0;
    }, 0, 3);
public void draw(){

Now for the testing purposes, the ball1 object is swinging around the midpoint of the screen, and the ball2 is just doing the same around the ball1 object.