原理:
这种效果的原理就是利用nineold提供的动画帮助类,做一个放大效果,子线程或者hanlder发消息延时两秒,然后对图片再执行放大效果,动画结束后跳转到首页
效果图:
添加依赖
代码语言:txt复制implementation 'com.nineoldandroids:library:2.4.0'
启动页布局文件
代码语言:txt复制<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@ id/img_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/default_splash"/>
</RelativeLayout>
代码实现逻辑
代码语言:txt复制public class SplashActivity extends AppCompatActivity {
private ImageView splash;
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);
splash = findViewById(R.id.img_splash);
//开启一个子线程执行跳转任务
new Thread() {
@Override
public void run() {
super.run();
try {
Thread.sleep(2000);
runOnUiThread(new Runnable() {
@Override
public void run() {
animateImage();
}
});
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}.start();
}
//放大图片
public void animateImage() {
//设置缩放动画
ObjectAnimator animatorX = ObjectAnimator.ofFloat(splash, "scaleX", 1f,
1.2f);
ObjectAnimator animatorY = ObjectAnimator.ofFloat(splash, "scaleY", 1f,
1.2f);
AnimatorSet set = new AnimatorSet();
set.setDuration(2000).play(animatorX).with(animatorY);
set.start();
//动画完成监听
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
//动画完成后跳转首页
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
}
});
}
}
需要源码的童鞋底部公众号回复:“闪屏动画” 即可获得哦.
到这里就结束啦.
小编整理了一份Android电子书籍,需要的童鞋关注公众号回复:"e_books" 即可获取哦!
欢迎关注公众号(longxuanzhigu),获得更多福利、精彩内容哦!