如何使gif图像显示为闪屏

时间:2016-09-27 06:04:07

标签: android android-studio animated-gif

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

3 个答案:

答案 0 :(得分: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"/>
    

答案 1 :(得分:0)

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

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

  1. 将.gif文件放入drawable文件夹
  2. 在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()
    }
    

答案 2 :(得分:0)

将webview设置为启动画面,让浏览器渲染gif。这就是全部!