黄沙百战穿金甲,不破楼兰终不还。这篇文章主要讲述Android插屏动画效果相关的知识,希望能为你提供帮助。
公司研发SDK,须要类似有米插屏的动画效果,研究了下,写了一个DEMO,凝视非常具体了。
【Android插屏动画效果】
文章图片
< span style="font-size:24px; "> package com.example.animationactivity; import android.animation.Animator; import android.animation.AnimatorSet; import android.animation.ObjectAnimato import android.annotation.SuppressLint; import android.content.Context; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.View; import android.view.View.OnClickListener; import android.view.WindowManager; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.AnimationUtils; import android.view.animation.ScaleAnimation; import android.view.animation.TranslateAnimation; import android.widget.Button; import android.widget.ImageView; import android.widget.RelativeLayout; @SuppressLint("NewApi") public class MainActivity extends ActionBarActivity { private Button button; ImageView image; private int a = 1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button) findViewById(R.id.button); image = new ImageView(getApplicationContext()); image.setImageDrawable(getResources().getDrawable(R.drawable.bg1)); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( (int) (getWidth(getApplicationContext()) * 0.8), (int) (getHeight(getApplicationContext()) * 0.8)); params.addRule(RelativeLayout.CENTER_IN_PARENT); RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.parent); image.setLayoutParams(params); relativeLayout.addView(image); /** // 动画1 final Animation animation = new TranslateAnimation(-600f, 0f, 0f, 0f); final Animation scaleAnimation = new ScaleAnimation(0.2f, 1f, 0.2f, 1f); final AnimationSet animationSet = new AnimationSet(true); animationSet.addAnimation(scaleAnimation); animationSet.addAnimation(animation); animationSet.setDuration(1000); Animation translationanimation = new TranslateAnimation(0f, 1800f, 0f, 0f); Animation scaleAnimation2 = new ScaleAnimation(1f, 0.4f, 1f, 0.4f); final AnimationSet animationSet2 = new AnimationSet(true); animationSet2.addAnimation(translationanimation); animationSet2.addAnimation(scaleAnimation2); animationSet2.setDuration(1000); animationSet2.setFillAfter(true); **/ button.setOnClickListener(new OnClickListener() {@SuppressLint("NewApi") @Override public void onClick(View v) { // TODO Auto-generated method stub // 自己写的 /** * if (a == 1) { a = 2; image.startAnimation(animationSet); } * else { a = 1; image.startAnimation(animationSet2); } **/// 从有米那里拷过来的动画 if (a == 1) { EnterAnimation(image, getApplicationContext()); a = 2; } else { BackAnimation(image, getApplicationContext()); a = 1; } } }); } // 获取屏幕的宽度 public static int getWidth(Context context) { WindowManager windowManager = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); int width = windowManager.getDefaultDisplay().getWidth(); return width; } // 获取屏幕的高度 public int getHeight(Context context) { WindowManager windowManager = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); int height = windowManager.getDefaultDisplay().getHeight(); return height; } // 出去动画 public static void BackAnimation(ImageView paramView, Context context) { int f = (getWidth(context) - paramView.getWidth()) / 2; paramView.setPivotX(paramView.getWidth() / 2); paramView.setPivotY(paramView.getHeight() / 2); ObjectAnimator localObjectAnimator1 = ObjectAnimator.ofFloat(paramView, "scaleX", new float[] { 1.0F, 0.8F }).setDuration(1L); ObjectAnimator localObjectAnimator2 = ObjectAnimator.ofFloat(paramView, "scaleY", new float[] { 1.0F, 0.8F }).setDuration(1L); ObjectAnimator localObjectAnimator3 = ObjectAnimator.ofFloat(paramView, "alpha", new float[] { 1.0F, 0.7F }).setDuration(1L); ObjectAnimator localObjectAnimator4 = ObjectAnimator.ofFloat(paramView, "X", new float[] { f, getWidth(context) }).setDuration(800L); ObjectAnimator localObjectAnimator5 = ObjectAnimator.ofFloat(paramView, "scaleX", new float[] { 0.8F, 1.0F }).setDuration(400L); localObjectAnimator5.setStartDelay(400L); ObjectAnimator localObjectAnimator6 = ObjectAnimator.ofFloat(paramView, "scaleY", new float[] { 0.8F, 1.0F }).setDuration(400L); localObjectAnimator6.setStartDelay(400L); ObjectAnimator localObjectAnimator7 = ObjectAnimator.ofFloat(paramView, "alpha", new float[] { 0.7F, 1.0F }).setDuration(400L); localObjectAnimator7.setStartDelay(400L); AnimatorSet localAnimatorSet = new AnimatorSet(); localAnimatorSet.playTogether(new Animator[] { localObjectAnimator1, localObjectAnimator2, localObjectAnimator3, localObjectAnimator4, localObjectAnimator5, localObjectAnimator6, localObjectAnimator7 }); localAnimatorSet.start(); } // 进入动画 public static void EnterAnimation(ImageView paramView, Context context) { // 屏幕的宽度减去动画的宽度。就是图片要移动的距离 int f = (getWidth(context) - paramView.getWidth()) / 2; paramView.setPivotX(paramView.getWidth() / 2); paramView.setPivotY(paramView.getHeight() / 2); ObjectAnimator localObjectAnimator1 = ObjectAnimator.ofFloat(paramView, "scaleX", new float[] { 1.0F, 0.8F }).setDuration(1L); ObjectAnimator localObjectAnimator2 = ObjectAnimator.ofFloat(paramView, "scaleY", new float[] { 1.0F, 0.8F }).setDuration(1L); ObjectAnimator localObjectAnimator3 = ObjectAnimator.ofFloat(paramView, "alpha", new float[] { 1.0F, 0.7F }).setDuration(1L); ObjectAnimator localObjectAnimator4 = ObjectAnimator.ofFloat(paramView, "X", new float[] { -paramView.getWidth(), f }) .setDuration(800L); ObjectAnimator localObjectAnimator5 = ObjectAnimator.ofFloat(paramView, "scaleX", new float[] { 0.8F, 1.0F }).setDuration(400L); localObjectAnimator5.setStartDelay(400L); ObjectAnimator localObjectAnimator6 = ObjectAnimator.ofFloat(paramView, "scaleY", new float[] { 0.8F, 1.0F }).setDuration(400L); localObjectAnimator6.setStartDelay(400L); ObjectAnimator localObjectAnimator7 = ObjectAnimator.ofFloat(paramView, "alpha", new float[] { 0.7F, 1.0F }).setDuration(400L); localObjectAnimator7.setStartDelay(400L); AnimatorSet localAnimatorSet = new AnimatorSet(); localAnimatorSet.playTogether(new Animator[] { localObjectAnimator1, localObjectAnimator2, localObjectAnimator3, localObjectAnimator4, localObjectAnimator5, localObjectAnimator6, localObjectAnimator7 }); localAnimatorSet.start(); }}< /span> < span style="font-size:18px; "> < /span>
推荐阅读
- 蜗牛—Android基础之button监听器
- spring mvc 之@requestmapping
- Process Stats:了解你的APP怎样使用内存
- android 到底是什么决定了app的名称 application label activity label
- 《深入理解Android2》读书笔记
- android出现anr(application not response)的分析
- Android开发-浅谈架构
- ppt怎样才能自动循环播放?在ppt中自动循环播放_PowerPoint专区
- word文档怎样插入批注?word插入批注的办法_Word专区