可以看到现在不少app都加入了开场动画,效果还是挺不错的,今天我就在这分享一下仿网易游戏的开场动画制作,同时我也在文章中加入了Android动画基础的详解,接下来就进入主题吧。
首先是布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
很简单,只是加入了一个Imageview由于放置开场图。
MainActivity代码:
public class MainActivity extends AppCompatActivity {
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView=(ImageView)findViewById(R.id.image);
imageView.setImageResource(R.drawable.netease);
AlphaAnimation animation = new AlphaAnimation(0, 1);
animation.setDuration(3000);
imageView.startAnimation(animation);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
alphaAnimation.setDuration(1500);
imageView.startAnimation(animation);
alphaAnimation.setFillAfter(true);
alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
Intent intent=new Intent(MainActivity.this,IndexActivity.class);
startActivity(intent);
MainActivity.this.finish();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
}
代码实现了仿网易游戏开场图渐变的效果,实际上这里只用到了