【问题标题】:How I can move each rectangle separately?如何分别移动每个矩形?
【发布时间】:2011-07-23 07:47:55
【问题描述】:

我有五个可绘制的矩形,我必须将矩形设置为 (-20,-15,-10,-5,0) 度角。每个矩形都有四种颜色阴影。现在我需要一个一个地为每个矩形设置动画,如果用户从左向右拖动,则顶部矩形从左向右移动。

问题是,我不能单独移动每个矩形。如何分别识别和实现每个矩形?

这里是我必须做的示例快照。 http://postimage.org/image/13sa96sbo/

public ColorFanDraw(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
}


@Override
protected void onDraw(Canvas canvasObject) {

    int x = 100;
    int y = 50;
    int width = 70;
    int convasSize =200;       

    Paint thePaint = new Paint();

    thePaint.setColor(mTouchedColor-200);   
    canvasObject.rotate(-15, centerX,centerY); 
    canvasObject.drawRect(new Rect(x,y,x+width,y+convasSize), thePaint);

    thePaint.setColor(mTouchedColor-50);    
    canvasObject.rotate(10, centerX,centerY);
    canvasObject.drawRect(new Rect(x,y,x+width,y+convasSize), thePaint);

    canvasObject.rotate(10, centerX,centerY);
    thePaint.setColor(mTouchedColor);
    canvasObject.drawRect(new Rect(x,y,x+width,y+convasSize), thePaint);

    rotation = AnimationUtils.loadAnimation(contextObj,
                                     R.anim.view_transition_in_left);

    ImageView img = new ImageView(contextObj);

    img.startAnimation(rotation);


}

【问题讨论】:

  • 您的问题是什么?没有问题,没有答案......

标签: android image animation move draw


【解决方案1】:

在将矩形对象绘制到画布上之前,您需要将它们存储在一个变量中。

Rect rectangle1 = new Rect(x,y,x+width,y+convasSize);
canvasObject.drawRect(rectangel1, thePaint);

Rect rectangle2 = new Rect(x,y,x+width,y+convasSize);
canvasObject.drawRect(rectangel2, thePaint);

等等。

然后,您可以在制作动画的任何位置引用各个矩形。

【讨论】:

    猜你喜欢
    • 2019-06-01
    • 2022-12-09
    • 1970-01-01
    • 2012-01-02
    • 2021-02-06
    • 2021-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多