android项目【新闻】项目实战(一):开发启动图并实现动画效果

一:创建android项目,结构如图

这里写图片描述

二:添加启动图的SplashActivity和布局文件

   布局文件代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/splash_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/splash_bg_newyear"
    tools:context="com.jingtong.hefeinews.SplashActivity">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/splash_sheep_newyear"/>
</RelativeLayout>
   SplashActivity代码如下:
public class SplashActivity extends AppCompatActivity {
    public static final String START_MAIN = "start_main";
    private RelativeLayout splash_root;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        splash_root = (RelativeLayout) findViewById(R.id.splash_root);
        //渐变动画
        AlphaAnimation alphaAnimation = new AlphaAnimation(0,1);
        //设置持续播放时间
        alphaAnimation.setDuration(500);
        alphaAnimation.setFillAfter(true);
        //缩放动画
        ScaleAnimation scaleAnimation = new ScaleAnimation(0,1,0,1,ScaleAnimation.RELATIVE_TO_SELF,0.5f,ScaleAnimation.RELATIVE_TO_SELF,0.5f);
        scaleAnimation.setDuration(500);
        scaleAnimation.setFillAfter(true);
        //旋转动画
        RotateAnimation rotateAnimation = new RotateAnimation(0,360,RotateAnimation.RELATIVE_TO_SELF,0.5f,RotateAnimation.RELATIVE_TO_SELF,0.5f);
        rotateAnimation.setDuration(500);
        rotateAnimation.setFillAfter(true);
        AnimationSet set = new AnimationSet(false);
        set.addAnimation(alphaAnimation);
        set.addAnimation(scaleAnimation);
        set.addAnimation(rotateAnimation);
        set.setDuration(2000);
        splash_root.startAnimation(set);
        set.setAnimationListener(new MyAnimationListenner());
    }
    //动画监听
    class MyAnimationListenner implements Animation.AnimationListener{

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            boolean isStartMain = CacheUtils.getBoolean(SplashActivity.this,START_MAIN);
            if (isStartMain){
                //如果进入过主页面,直接进入主页面
            }else {
                //如果没有进入过主页面,进入向导界面
                Intent intent = new Intent(SplashActivity.this,GuideActivity.class);
                startActivity(intent);
            }
            finish();
            Toast.makeText(SplashActivity.this, "播放完成", Toast.LENGTH_SHORT).show();

        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    }

}

动态效果图:这里写图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值