【问题标题】:How to make gif image appear as splash screen如何使 gif 图像显示为闪屏
【发布时间】:2016-09-27 06:04:07
【问题描述】:

我想在我的 android 应用程序中将 gif 图像显示为五秒钟(不使用 webview)。如果我正在使用 ImageView,并向其中添加 Gif,它不会显示为一般图像。请对此提供帮助。

【问题讨论】:

  • 使用 glide 支持 gif
  • 感谢 SilentKiller 的回复......直到现在我已经尝试将 gif 图像作为源添加到 imageView 但它只是显示为 Jpg 格式图像

标签: android android-studio animated-gif


【解决方案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"/>
    

【讨论】:

    【解决方案2】:

    1.输入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()
    }
    

    【讨论】:

    • 感谢您回复 n9153,出现错误...无法解析 compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.+
    • 你到底在哪里得到这个错误?您是否将其添加为 gradle 依赖项?
    • 是我的 gradle 依赖项,依赖项 { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'pl.droidsonroids.gif:android-gif-drawable: 1.1.+' testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.3.0' }
    • @EED 您是否将maven 添加到您的build.gradle 顶级依赖项中。
    • 好的。如果我在 build.gradle 的依赖项中添加单行“compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.+'”可以吗?如果是 YES ,在这种情况下我会收到错误,无法解析编译'pl.droidsonroids.gif:android-gif-drawable:1.1.+'。如何摆脱这个错误。请帮助我
    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-30
      • 1970-01-01
      • 2011-02-04
      • 1970-01-01
      • 2011-06-17
      • 2011-03-06
      • 2017-02-13
      相关资源
      最近更新 更多