显示Gif图片的Android组件:android-gif-drawable

jopen 10年前

android-gif-drawable是一个用于显示GIF图片的Android组件。能很好的解决OOM问题。

From XML    提供最简便的方式来使用GifImageView (or GifImageButton)就像一个正常的ImageView:    <pl.droidsonroids.gif.GifImageView      android:layout_width="match_parent"      android:layout_height="match_parent"      android:src="@drawable/src_anim"      android:background="@drawable/bg_anim"      />
From Java code    GifImageView, GifImageButton and GifTextView have also hooks for setters implemented. So animated GIFs can be set by calling setImageResource(int resId) and setBackgroundResource(int resId)    GifDrawable can be constructed directly from various sources:            //asset file          GifDrawable gifFromAssets = new GifDrawable( getAssets(), "anim.gif" );            //resource (drawable or raw)          GifDrawable gifFromResource = new GifDrawable( getResources(), R.drawable.anim );            //byte array          byte[] rawGifBytes = ...          GifDrawable gifFromBytes = new GifDrawable( rawGifBytes );            //FileDescriptor          FileDescriptor fd = new RandomAccessFile( "/path/anim.gif", "r" ).getFD();          GifDrawable gifFromFd = new GifDrawable( fd );            //file path          GifDrawable gifFromPath = new GifDrawable( "/path/anim.gif" );            //file          File gifFile = new File(getFilesDir(),"anim.gif");          GifDrawable gifFromFile = new GifDrawable(gifFile);            //AssetFileDescriptor          AssetFileDescriptor afd = getAssets().openFd( "anim.gif" );          GifDrawable gifFromAfd = new GifDrawable( afd );            //InputStream (it must support marking)          InputStream sourceIs = ...          BufferedInputStream bis = new BufferedInputStream( sourceIs, GIF_LENGTH );          GifDrawable gifFromStream = new GifDrawable( bis );            //direct ByteBuffer          ByteBuffer rawGifBytes = ...          GifDrawable gifFromBytes = new GifDrawable( rawGifBytes );

项目主页:http://www.open-open.com/lib/view/home/1406381565164