如何使gif图像显示为闪屏

问题描述 投票:-4回答:3

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

android android-studio animated-gif
3个回答
0
投票

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

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

  1. 将.gif文件放在drawable文件夹中

在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"
                />

转到您的Project Level build.gradle文件,如果不存在则添加以下代码

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

或者你也可以试试

repositories {
    jcenter()
}

1
投票

试试这个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"/>

0
投票

将webview设置为启动画面,然后让浏览器渲染gif。就这样!

© www.soinside.com 2019 - 2024. All rights reserved.