android动画(二)之动画

1.camera由远到近特效(缩放动画)

首先新建一个布局文件camera_stretch_activity

 

具体代码

ImageView imageView = findViewById(R.id.img); ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f,1.2f,1.0f,1.2f, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); scaleAnimation.setFillAfter(true); scaleAnimation.setInterpolator(new BounceInterpolator()); scaleAnimation.setDuration(6000); imageView.startAnimation(scaleAnimation);

这里的插值器选择的是回弹插值器 

2.旋转动画效果   数据加载进度

布局文件loading:

具体代码:

ImageView imageView = findViewById(R.id.loading); RotateAnimation rotateAnm = new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); rotateAnm.setRepeatCount(Animation.INFINITE); rotateAnm.setDuration(2000); rotateAnm.setInterpolator(new LinearInterpolator()); imageView.startAnimation(rotateAnm);

3  位移动画

布局文件:

具体代码:

final TextView tv = findViewById(R.id.tv); Button btn = findViewById(R.id.btn); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { TranslateAnimation animation = new TranslateAnimation(Animation.ABSOLUTE,0, Animation.ABSOLUTE,400,Animation.ABSOLUTE,0,Animation.ABSOLUTE,100); animation.setFillAfter(true); animation.setDuration(1000); tv.startAnimation(animation); } });

4.ValueAnimator属性动画实现位移动画效果

结合上面的布局文件使用ValueAnimator实现位移动画效果

private void doAnimation() { ValueAnimator animator = ValueAnimator.ofInt(0, 400); animator.setDuration(1000); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { int curValue = (int) animation.getAnimatedValue(); tv.layout(curValue, curValue, curValue + tv.getWidth(), curValue + tv.getHeight()); } }); animator.start(); 

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