2016-09-27 114 views
-4

我想在我的android應用程序中以五秒鐘的時間顯示gif圖像(不使用webview)。如果我正在使用ImageView,並向它添加Gif,它不會顯示爲一般Image.Please有關這方面的幫助。如何使gif圖像顯示爲啓動畫面

+0

使用滑翔 – Stallion

+0

感謝您迴應SilentKiller ....到現在我已經嘗試添加gif圖片作爲源的ImageView,但它只是顯示爲JPG格式的圖像 – EED

回答

0

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

在你的build.gradle文件中的依賴

  • 把你的.gif文件的文件夾繪製
  • 調用下面的方法在您的onCreate的SplashActivity

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

    轉到您的項目級別的構建.gradle文件並添加下面的代碼,如果它不存在

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

    或者您也可以嘗試

    repositories { 
        jcenter() 
    } 
    
    +0

    感謝您迴應n9153, 得到一個錯誤...未能解決編譯'pl.droidsonroids.gif:android-gif-drawable:1.1。+ – EED

    +0

    你究竟在哪裏得到這個錯誤?你有沒有添加這個作爲gradle依賴? – Nishith

    +0

    ya它是我的gradle依賴關係, 依賴項編譯文件樹(dir:'libs',include:['* .jar']) compile'pl.droidsonroids.gif:android-gif-drawable:1.1。+' testCompile'junit:junit:4.12' compile'c​​om.android.support:appcompat-v7:23.3.0' } – EED

    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。就這樣!對於GIF支持