我有五个形状绘制矩形,我必须设置角度为(-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);
}
答案 0 :(得分:0)
在将矩形对象绘制到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);
等等。
然后,无论在哪里进行动画,都可以参考各个矩形。