如何使 gif 图像显示为启动画面

How to make gif image appear as splash screen

我想在我的 android 应用程序中将 gif 图像显示为启动画面五秒钟(不使用 webview)。如果我正在使用 ImageView,并向其中添加 Gif,它不会显示为一般性 Image.Please 相关帮助。

1.Put compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.+'

在您的 build.gradle 文件中作为依赖项。

  1. 将您的 .gif 文件放在可绘制文件夹中

在 SplashActivity 的 onCreate 中调用以下方法

public void startSplash(){
        Animation fadeout = new AlphaAnimation(1.f, 1.f);
        fadeout.setDuration(2500);
        final View viewToAnimate = gifImageView;
        fadeout.setAnimationListener(new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
                gifImageView.setBackgroundResource(R.drawable.splash_screen);//splash_screen is your .gif file
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {

        });
        gifImageView.startAnimation(fadeout);
    }


 Put the below code in your SplashActivty.xml

     <pl.droidsonroids.gif.GifTextView
                android:id="@+id/imageView"
                android:layout_width="fill_parent"
                android:scaleType="fitXY"
                android:layout_height="fill_parent"
                />

转到您的项目级别 build.gradle 文件并添加以下代码(如果不存在)

buildscript {
    repositories {
        mavenCentral()
    }
}
allprojects {
    repositories {
        mavenCentral()
    }
}

或者你也可以试试

repositories {
    jcenter()
}

试试这个 gif 视图

  1. 使用依赖项

    compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.17'
    
  2. 将 Imageview 替换为此 XML

    <pl.droidsonroids.gif.GifImageView
     android:layout_width="match_parent"
     android:layout_centerInParent="true"
     android:layout_height="match_parent"
     android:src="@drawable/splashbg"/>
    

将 webview 设置为启动画面并让浏览器呈现 gif。就这些!