Android 模拟电视机开关机的动画效果
2017-06-16 16:42
309 查看
话不多说先上图:
关机动画
开机动画
MainActivity调用
关机动画
public class TVOffAnimation extends Animation { private int halfWidth; private int halfHeight; @Override public void initialize(int width, int height, int parentWidth, int parentHeight) { super.initialize(width, height, parentWidth, parentHeight); setDuration(1000); setFillAfter(true); //保存View的中心点 halfWidth = width / 2; halfHeight = height / 2; setInterpolator(new AccelerateDecelerateInterpolator()); } @Override protected void applyTransformation(float interpolatedTime, Transformation t) { final Matrix matrix = t.getMatrix(); if (interpolatedTime < 0.8) { matrix.preScale(1+0.625f*interpolatedTime, 1-interpolatedTime/0.8f+0.01f,halfWidth,halfHeight); }else{ matrix.preScale(7.5f*(1-interpolatedTime),0.005f,halfWidth,halfHeight); } } }
开机动画
public class TVOpenAnimation extends Animation { private int halfWidth; private int halfHeight; @Override public void initialize(int width, int height, int parentWidth, int parentHeight) { super.initialize(width, height, parentWidth, parentHeight); setDuration(1000); setFillAfter(true); //保存View的中心点 halfWidth = width / 2; halfHeight = height / 2; setInterpolator(new AccelerateDecelerateInterpolator()); } @Override protected void applyTransformation(float interpolatedTime, Transformation t) { final Matrix matrix = t.getMatrix(); /* if (interpolatedTime < 0.8) { matrix.preScale(1 + 0.625f * interpolatedTime, 1 - interpolatedTime / 0.8f + 0.01f, halfWidth, halfHeight); } else { matrix.preScale(7.5f * (1 - interpolatedTime), 0.01f, halfWidth, halfHeight); }*/ if (interpolatedTime<0.4) { matrix.preScale( interpolatedTime / (1-0.8f),0.005f,halfWidth,halfHeight); }else { matrix.preScale(1,interpolatedTime,halfWidth,halfHeight); } } }
MainActivity调用
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.button); Button button2 = (Button) findViewById(R.id.button2); Button button3 = (Button) findViewById(R.id.button3); final View view = findViewById(R.id.activity_main); final ImageView imageView = (ImageView) findViewById(R.id.img); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { imageView.startAnimation(new TVOffAnimation()); } }); button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Animation animation = AnimationUtils.loadAnimation(MainActivity.this,R.anim.duang); imageView.startAnimation(new TVOpenAnimation()); } }); //这是弹球效果的代码 button3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int mHeight = imageView.getHeight(); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(ObjectAnimator.ofFloat(imageView,"translationY",-mHeight,0).setDuration(2000)); animatorSet.setInterpolator(new BounceInterpolator()); animatorSet.start(); } }); }
相关文章推荐
- 【2013-09-10 09:52 星期二 Android动画------ 模拟电视机关闭屏幕效果】
- Android 动画-->自定义3D动画效果和模拟电视机关闭效果的动画
- 移植Android银河动态壁纸源码,在windows上模拟效果(动画)
- android 组件动画(一)——球的进入效果
- Android 开发笔记 动画效果 --Animation
- [Android1.5]Android2.0版本以下Activity切换动画效果
- Android2.0版本以下Activity切换动画效果
- android 页面切换动画效果
- Android动画开发——Animation动画效果
- 动画效果编程基础--AnimationAndroid
- [Android][UI]模拟器启动界面动画效果的简单实现
- 动画效果编程基础--AnimationAndroid
- Google Android新SDK放出 可创造出动画效果
- 《转》动画效果编程基础--AnimationAndroid
- Android/OPhone动画分析之翻转效果
- Android之动画效果编程基础
- 写了一个android带动画翻页效果的程序
- Silverlight动画基础三:动画与向量-模拟重力效果
- Android 电视关闭的动画效果