android中动画的学习

		ImageView iv = (ImageView) findViewById(R.id.imageView1);
		
				ObjectAnimator obj = ObjectAnimator.ofFloat(iv, "alpha",0f, 1f);
				obj.setDuration(2000);
				obj.start();
				
				obj = ObjectAnimator.ofFloat(iv,"rotationX",0.0f,180.0f,180.0f,0.0f);
				obj.setDuration(5000);
				obj.setRepeatMode(Animation.REVERSE);
				obj.start();

		
		//-----------------------------------------------------------------------------------------
//		iv.setOnClickListener(new OnClickListener() {
//
//			@Override
//			public void onClick(final View v) {
//				Log.d("liuhang","===============");
//
//				//	ObjectAnimator obj = ObjectAnimator.ofFloat(v,"rotationY",0.0f,180.0f,180.0f,0.0f);
//				//	obj.setDuration(3000);
//				//	obj.start();
//
//				ObjectAnimator obj = ObjectAnimator.ofFloat(v, "liuhang",0.0f,1.3f,1.3f,1.0f).setDuration(3000);
//				obj.start();
//				obj.addUpdateListener(new AnimatorUpdateListener() {
//
//					@Override
//					public void onAnimationUpdate(ValueAnimator animation) {
//
//						float cVal = (Float) animation.getAnimatedValue();
//						v.setAlpha(cVal);
//						v.setScaleX(cVal);
//						v.setScaleY(cVal);
//					}
//				});
//			}
//		}); 

		//-----------------------------------------------------------------------------------------
		
//		usePropertyValueHolder(iv);



		//-----------------------------------------------------------------------------------------
		ObjectAnimator obj = ObjectAnimator.ofFloat(iv,"alpha",0.5f);
		obj.addListener(new AnimatorListener() {
			
			@Override
			public void onAnimationStart(Animator animation) {
				// TODO Auto-generated method stub
				
				Log.d(tag, "animation start");
			}
			
			@Override
			public void onAnimationRepeat(Animator animation) {
				// TODO Auto-generated method stub
				Log.d(tag, "animation repeat");
			}
			
			@Override
			public void onAnimationEnd(Animator animation) {
				// TODO Auto-generated method stub
				Log.d(tag, "animation end");
			}
			
			@Override
			public void onAnimationCancel(Animator animation) {
				// TODO Auto-generated method stub
				Log.d(tag, "animation cancel");
			}
		});
		obj.start();


	}


	public void usePropertyValueHolder(View view) {
		PropertyValuesHolder vhAlpha = PropertyValuesHolder.ofFloat("alpha",1f,0f,1f);
		PropertyValuesHolder vhScaleX = PropertyValuesHolder.ofFloat("scaleX",1f,0f,1.5f,1.0f);
		PropertyValuesHolder vhScaleY = PropertyValuesHolder.ofFloat("scaleY",1f,0f,1.5f,1.0f);
		ObjectAnimator.ofPropertyValuesHolder(view, vhAlpha,vhScaleX,vhScaleY).setDuration(3000).start();
	}

多个动画同时运行

public void togetherRun(View view) {
		
		ObjectAnimator animationOne = ObjectAnimator.ofFloat(view, "scaleX",1.0f,2.0f,1.0f);
		ObjectAnimator animationTwo = ObjectAnimator.ofFloat(view, "scaleY",1.0f,2.0f,1.0f);
		AnimatorSet sets = new AnimatorSet();
		sets.setInterpolator(new AccelerateDecelerateInterpolator());
		sets.playTogether(animationOne,animationTwo);
		sets.setDuration(3000);
		sets.start();
	}


你可能感兴趣的:(android,动画)