0

我有圆圈的数组列表,whitch 正在画布上绘制。一切都很好。但我需要在程序期间更改所有 X、Y 坐标。

static ArrayList<Circle> mCircles;

private static void createCircles() {
    if (mCircles == null) { 
        mCircles = new ArrayList<Circle>();
    }

    int rana = 66/(koeficient);
    mCircles.add(new Circle(80, 200, rana));
}

public static void AddCircle() {
    int rana = 66/(koeficient);

    mCircles.add(new Circle(80, 200, rana));
}

private void Drawing(Canvas canvas) {
    for (Circle c : mCircles) {
        canvas.drawCircle(c.getCurrentX(), c.getCurrentY(), c.getRadius(),
                            mMalovani);
    }
}

public static Circle findCircleClosestToTouchEvent(float x, float y) {
    Circle c = mCircles.get(mCircles.size() - 1);

    return c;
}

公共类圆形扩展形状{

final float mRadius;




public Circle(float x, float y, float r) {
    super(x, y);
    mRadius = r;
}

final float getRadius() {
    return mRadius;
}

}

公共类形状扩展活动{

protected float mStartX   = 0f;
protected float mStartY   = 0f;
public float mCurrentX = 30f;   
public float mCurrentY = 30f;   
protected float mActionDownX;       
protected float mActionDownY;       
protected float mActionMoveOffsetX; 
protected float mActionMoveOffsetY;



// x y coordinate of a move action

public Shape (float x, float y) {
    mStartX   = x;
    mStartY   = y;
    mCurrentX = x;
    mCurrentY = y;



}








public void setStartX(float x) { mStartX = x; }

public void setStartY(float y) { mStartY = y; }

public float getCurrentX() { return mCurrentX; }

public float getCurrentY() { return mCurrentY; }







public void setCurrentX(float x) { mCurrentX = x;

}

public void setCurrentY(float y) { mCurrentY = y; }

public void setActionMoveOffsetX(float x) { mActionMoveOffsetX = x; }

public void setActionMoveOffsetY(float y) { mActionMoveOffsetY = y; }

public float getActionMoveOffsetX() { return mActionMoveOffsetX; }

public float getActionMoveOffsetY() { return mActionMoveOffsetY; }

public void setActionDownX(float x) { mActionDownX = x; }

public void setActionDownY(float y) { mActionDownY = y; }

public float getActionDownX() { return mActionDownX; }

public float getActionDownY() { return mActionDownY; }





public void restoreStartPosition() {
    mCurrentX = mStartX;
    mCurrentY = mStartY;
}

}

4

1 回答 1

1

Assuming you have setCurrentX and setCurrentY methods opposite the getter methods, just loop through the list of circles.

  private void changeCoordinates(List<Circle> circles, int x, int y){
       for(Circle c:circles){
          c.setCurrentX(x);
          c.setCurrentY(y);
       }
    }
于 2013-08-27T08:38:26.710 回答