Android開源項目:GifView——Android顯示GIF動畫

來源:互聯網
上載者:User

標籤:image   listen   ant   構造   you   屬性   log   ima   一個   

下載:http://code.google.com/p/gifview/downloads/list

簡介:android中現在沒有直接顯示gif的view,只能通過mediaplay來顯示,且還常常不能正常顯示出來,為此寫了這個gifview,其用法和imageview一樣

使用方法:

1-把GifView.jar加入你的項目。

2-在xml中配置GifView的基本屬性,GifView繼承自View類,和Button、ImageView一樣是一個UI控制項。如:

<com.ant.liao.GifView android:id="@+id/gif2"      android:layout_height="wrap_content" android:layout_width="wrap_content"      android:paddingTop="4px" android:paddingLeft="14px" android:enabled="false" />

3-在代碼中配置常用屬性:

// 從xml中得到GifView的控制代碼      gf1 = (GifView) findViewById(R.id.gif1);      // 設定Gif圖片源      gf1.setGifImage(R.drawable.gif1);      // 添加監聽器      gf1.setOnClickListener(this);      // 設定顯示的大小,展開或者壓縮      gf1.setShowDimension(300, 300);      // 設定載入方式:先載入後顯示、邊載入邊顯示、只顯示第一幀再顯示      gf1.setGifImageType(GifImageType.COVER);  

GifView的Jar包共有四個類:

GifAction.java:

觀察者類,監視GIF是否載入成功

package com.ant.liao;    public interface GifAction {  /**   *gif解碼觀察者   * @hide   * @param parseStatus 解碼是否成功,成功會為true              * @param frameIndex 當前解碼的第幾幀,當全部解碼成功後,這裡為-1              */       public void parseOk(boolean parseStatus,int frameIndex);  }    

GifView的Jar包共有四個類:

GifAction.java:

觀察者類,監視GIF是否載入成功

package com.ant.liao;    public interface GifAction {  /**   *gif解碼觀察者   * @hide   * @param parseStatus 解碼是否成功,成功會為true              * @param frameIndex 當前解碼的第幾幀,當全部解碼成功後,這裡為-1              */       public void parseOk(boolean parseStatus,int frameIndex);  }    

GifFrame.java

裡面三個成員:當前圖片、延時、下張Frame的連結。

package com.ant.liao;  import android.graphics.Bitmap;  public class GifFrame {   /** * 建構函式  * @param im 圖片  * @param del 延時  */          public GifFrame(Bitmap im, int del) {    image = im;           delay = del;       }             public GifFrame(String name,int del){     imageName = name;           delay = del;          }                 /**圖片*/        public Bitmap image;     /**延時*/          public int delay;    /**當圖片存成檔案時的檔案名稱*/   public String imageName = null;        /**下一幀*/        public GifFrame nextFrame = null;   }    

 

Android開源項目:GifView——Android顯示GIF動畫

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.