android tween animation 补间动画

来源:互联网 发布:高仿包 淘宝 编辑:程序博客网 时间:2024/05/03 23:00
public class MainActivity extends Activity {private ImageView imageView;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);imageView = (ImageView) findViewById(R.id.image);}/*** 透明度* * @param view*/public void click1(View view) {// 两个参数分别代表动画图片开始的透明度和结束的透明度AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);// 设置动画的时间长度animation.setDuration(2000);// 设置动画播放的重复次数,设置为2代表一共播放3次animation.setRepeatCount(2);// 设置重复的模式,Animation.REVERSE代表往返重复animation.setRepeatMode(Animation.REVERSE);imageView.startAnimation(animation);}/*** 缩放* * @param view*/public void click2(View view) {// 0.2f(X或Y方向的开始缩放大小为图片的20%) 1.0f(X或Y方向的结束缩放大小为图片的100%)// Animation.RELATIVE_TO_SELF(以自身相关来改变) 0.5f(X和Y以自身的中心圆点来缩放)ScaleAnimation animation = new ScaleAnimation(0.2f, 1.0f, 0.2f, 1.0f,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);animation.setDuration(2000);animation.setRepeatCount(2);animation.setRepeatMode(Animation.REVERSE);imageView.startAnimation(animation);}/*** 旋转* * @param view*/public void click3(View view) {RotateAnimation animation = new RotateAnimation(0, 360,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);animation.setDuration(2000);animation.setRepeatCount(2);animation.setRepeatMode(Animation.REVERSE);imageView.startAnimation(animation);} /*** 平移* * @param view*/public void click4(View view) {// 水平移动TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,Animation.RELATIVE_TO_PARENT, 1.0f,Animation.RELATIVE_TO_PARENT, 0.0f,Animation.RELATIVE_TO_PARENT, 0.0f);animation.setDuration(2000);animation.setRepeatCount(2);animation.setRepeatMode(Animation.REVERSE);imageView.startAnimation(animation);}/*** 组合* * @param view*/public void click5(View view) {AnimationSet animationSet = new AnimationSet(false);ScaleAnimation scaleAnimation = new ScaleAnimation(0.2f, 1.0f, 0.2f,1.0f, Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF, 0.5f);scaleAnimation.setDuration(2000);scaleAnimation.setRepeatCount(2);scaleAnimation.setRepeatMode(Animation.REVERSE);RotateAnimation rotateAnimation = new RotateAnimation(0, 360,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);rotateAnimation.setDuration(2000);rotateAnimation.setRepeatCount(2);rotateAnimation.setRepeatMode(Animation.REVERSE);TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,Animation.RELATIVE_TO_PARENT, 1.0f,Animation.RELATIVE_TO_PARENT, 0.0f,Animation.RELATIVE_TO_PARENT, 0.0f);translateAnimation.setDuration(2000);translateAnimation.setRepeatCount(2);translateAnimation.setRepeatMode(Animation.REVERSE);animationSet.addAnimation(translateAnimation);animationSet.addAnimation(rotateAnimation);animationSet.addAnimation(scaleAnimation);                // 把平移、旋转、缩放结合在一起的动画imageView.startAnimation(animationSet);}}


0 0
原创粉丝点击