0
点赞
收藏
分享

微信扫一扫

【转载】【Android】Splash animation effect

天蓝Sea 2022-02-15 阅读 96

实现:
1.build.gradle中添加库

implementation 'com.airbnb.android:lottie:3.4.1'

2.将图片放到drawable目录下:
将动态json文件放到app\src\main\res\raw目录下
3.在布局文件中添加如下:

    <ImageView
        android:id="@+id/img"
        android:layout_width="wrap_content"
        android:layout_height="900dp"
        android:scaleType="centerCrop"
        android:src="@drawable/bg"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>

    <ImageView
        android:id="@+id/app_name"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:src="@drawable/app_name"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.495"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.181" />

    <com.airbnb.lottie.LottieAnimationView
        android:id="@+id/lottie"
        android:layout_width="wrap_content"
        android:layout_height="300dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:lottie_autoPlay="true"
        app:lottie_rawRes="@raw/splash" />

4:在Java中添加如下:

splashimg.animate().translationY(-2500).setDuration(1000).setStartDelay(5000);
appname.animate().translationY(2000).setDuration(1000).setStartDelay(5000);
lottieAnimationView.animate().translationY(1500).setDuration(1000).setStartDelay(5000);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                startActivity(new Intent(splash.this,MainActivity.class));
				finish();
            }
        },6000);

参考连接:
https://lottiefiles.com/
https://github.com/foxandroid/Splashscreenanimation
https://www.youtube.com/watch?v=Amg4JKylQlw

举报

相关推荐

0 条评论