标签:des android cWeb style blog http io color os
1.概要:
新的动画API通常可以比旧的API实现更多嵌在功能,一下是新API一些改进的简短列表。
2.要想向读者展示在图像幻灯片里模式ken Burns特效,就要用到一个动画库(Nine Old Android)库这个库可以让开发者在旧版本上使用Andorid3.0的动画API
1 public class MainActivity extends Activity implements AnimatorListener { 2 private FrameLayout container; 3 private ImageView mImg; 4 private int[] imageIDs = { R.drawable.photo1, R.drawable.photo2, 5 R.drawable.photo3, R.drawable.photo4, R.drawable.photo5, 6 R.drawable.photo6 }; 7 private int mIndex; 8 9 private Random mRandom; 10 11 @Override 12 protected void onCreate(Bundle savedInstanceState) { 13 super.onCreate(savedInstanceState); 14 mRandom = new Random(); 15 container = new FrameLayout(MainActivity.this); 16 container.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 17 LayoutParams.MATCH_PARENT)); 18 mImg = createImageView(); 19 container.addView(mImg); 20 setContentView(container); 21 } 22 23 @Override 24 protected void onResume() { 25 super.onResume(); 26 doAniamtion(); 27 } 28 29 private ImageView createImageView() { 30 ImageView img = new ImageView(MainActivity.this); 31 img.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 32 LayoutParams.MATCH_PARENT)); 33 img.setScaleType(ScaleType.FIT_XY); 34 img.setBackgroundResource(imageIDs[mIndex]); 35 mIndex = (mIndex+1 < imageIDs.length) ? mIndex+1 : 0; 36 return img; 37 } 38 39 private void doAniamtion() { 40 // 对view进行随机动画 41 AnimatorSet set = new AnimatorSet(); 42 int index = mRandom.nextInt(imageIDs.length); 43 switch (index) { 44 case 0: 45 set.playTogether(ObjectAnimator.ofFloat(mImg, "scaleX", 1.5f, 1f), 46 ObjectAnimator.ofFloat(mImg, "scaleY", 1.5f, 1f)); 47 48 break; 49 case 1: 50 set.playTogether(ObjectAnimator.ofFloat(mImg, "scaleX", 1, 1.5f), 51 ObjectAnimator.ofFloat(mImg, "scaleY", 1, 1.5f)); 52 53 break; 54 case 2: 55 56 set.playTogether(ObjectAnimator.ofFloat(mImg, "rotationX", 0.0f, 57 360.0f)); 58 break; 59 case 3: 60 AnimatorProxy.wrap(mImg).setScaleX(1.5f); 61 AnimatorProxy.wrap(mImg).setScaleY(1.5f); 62 set.playTogether(ObjectAnimator.ofFloat(mImg, "translationY", 80f, 63 0f)); 64 break; 65 default: 66 break; 67 68 } 69 70 set.setDuration(3000); 71 set.addListener(this); 72 set.start(); 73 74 } 75 76 @Override 77 public void onAnimationCancel(Animator arg0) { 78 79 } 80 81 @Override 82 public void onAnimationEnd(Animator arg0) { 83 container.removeView(mImg); 84 mImg = createImageView(); 85 container.addView(mImg); 86 doAniamtion(); 87 } 88 89 @Override 90 public void onAnimationRepeat(Animator arg0) { 91 92 } 93 94 @Override 95 public void onAnimationStart(Animator arg0) { 96 97 } 98 99 }
HackEight附加Ken Burns特效的幻灯片(属性动画的使用)
标签:des android cWeb style blog http io color os
原文地址:http://www.cnblogs.com/liangstudyhome/p/4058177.html