如何单独移动每个矩形?

发布于 2024-11-26 11:27:14 字数 1287 浏览 1 评论 0原文

我有五个形状可绘制矩形,我必须将矩形设置为(-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);


}

I have five shape draw able rectangular, I have to set the rectangle at angle of (-20,-15,-10,-5,0)Degree. Each Rectangular have four colors shade. Now I need to animate each rectangle one by one and if user drag left to right then top rectangle moves to left to right.

Problem is, I can’t move each rectangle separately. How I can identify and implement each rectangle separately?

Here sample snapshot that i have to do.
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);


}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坐在坟头思考人生 2024-12-03 11:27:14

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

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);

等等。

然后,无论您在哪里制作动画,都可以引用各个矩形。

You would need to store the rectangle objects in a variable before you draw them onto the Canvas.

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);

and so on.

Then you can refer to the individual rectangles wherever you are doing your animation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文