开发者

How I can move each rectangle separately?

开发者 https://www.devze.com 2023-03-22 04:44 出处:网络
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 i

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


}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号