Code example for AnimatorSet

Methods: playSequentially, playTogether, start

0
					} 
				}); 
 
				// ============================================================= 
				// 用一个总的AnimatorSet对象管理以上所有动画 
				animation = new AnimatorSet();
				animation.playTogether(anim1, anim2, s1);// 并行
				animation.playSequentially(s1, s2, valueAnimator5);// 串行
			} 
		} 
 
		// 在指定位置加上球形 
		private ShapeHolder addBall(float x, float y) {
			OvalShape circle = new OvalShape();
			circle.resize(50f * mDensity, 50f * mDensity);
			ShapeDrawable drawable = new ShapeDrawable(circle);
			ShapeHolder shapeHolder = new ShapeHolder(drawable);
			shapeHolder.setX(x - 25f);
			shapeHolder.setY(y - 25f);
			int red = (int) (100 + Math.random() * 155);
			int green = (int) (100 + Math.random() * 155);
			int blue = (int) (100 + Math.random() * 155);
			int color = 0xff000000 | red << 16 | green << 8 | blue;
			Paint paint = drawable.getPaint(); // new
												// Paint(Paint.ANTI_ALIAS_FLAG); 
			int darkColor = 0xff000000 | red / 4 << 16 | green / 4 << 8 | blue
					/ 4; 
			RadialGradient gradient = new RadialGradient(37.5f, 12.5f, 50f,
					color, darkColor, Shader.TileMode.CLAMP);
			paint.setShader(gradient);
			shapeHolder.setPaint(paint);
			balls.add(shapeHolder);
			return shapeHolder;
		} 
 
		@Override 
		protected void onDraw(Canvas canvas) {
			// 遍历并绘制每一个球形对象 
			for (int i = 0; i < balls.size(); ++i) {
				ShapeHolder shapeHolder = balls.get(i);
				canvas.save();
				canvas.translate(shapeHolder.getX(), shapeHolder.getY());
				shapeHolder.getShape().draw(canvas);
				canvas.restore();
			} 
		} 
 
		public void startAnimation() { 
			createAnimation(); 
			animation.start();// 这里开始播放动画
		} 
 
		@Override 
		public void onAnimationUpdate(ValueAnimator animation) {
			// 在参数更新的时候invalidate,刷新整个View的绘制