效果很简单,先上图先
package viewpager.view.com.org.myviewpager;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.widget.RelativeLayout;
public class SplashActivity extends Activity {
private RelativeLayout relativeLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置全屏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_splash);
relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
// 旋转
RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(1000);
rotateAnimation.setFillAfter(true);
//缩放
ScaleAnimation scaleAnimation = new ScaleAnimation(0,1,0,1,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(1000);
scaleAnimation.setFillAfter(true);
//渐变
AlphaAnimation alphaAnimation = new AlphaAnimation(0,1);
alphaAnimation.setDuration(2000);
alphaAnimation.setFillAfter(true);
<span style="white-space:pre"> </span>//把每个效果到放进来
AnimationSet animationSet = new AnimationSet(true);
animationSet.addAnimation(rotateAnimation);
animationSet.addAnimation(scaleAnimation);
animationSet.addAnimation(alphaAnimation);
relativeLayout.startAnimation(animationSet);
//设置AnimationListener
animationSet.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) { //Animation开始调用的方法
}
@Override
public void onAnimationEnd(Animation animation) { // <span style="font-family: Arial, Helvetica, sans-serif;">Animation结束调用的方法</span>
<span style="white-space:pre"> </span>
}
@Override
public void onAnimationRepeat(Animation animation) {// Animation重复调用的方法
}
});
}
}
这个是开始动画的Activity
再发个XML布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash_bg_newyear"
android:id="@+id/relativeLayout"
tools:context="viewpager.view.com.org.myviewpager.SplashActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/splash_horse_newyear"/>
</RelativeLayout>
再发一张我的工程目录结构,因为要用到图片,所以事先把图片copy到工程里
对了!设置Animation部分有3个方法是Animation开始调用的,然后在里面可以写一些运行完动画之后,进入到主界面的Activity
OK! 就这样!Thank you very much!