如何使用
-
和使用ImageView一样
<com.felipecsl.gifimageview.library.GifImageView
android:id="@+id/gifImageView"android:layout_gravity="center"android:scaleType="fitCenter"android:layout_width="match_parent"android:layout_height="match_parent"/>
2. 你需要用java设置图片,
gifImageView = (GifImageView) findViewById(R.id.gifImageView);
InputStream is = this.getResources().openRawResource(R.drawable.image01);try {ByteArrayOutputStream baos = new ByteArrayOutputStream();byte[] b = new byte[2048];int len = 0;while ((len = is.read(b, 0, 2048)) != -1) {baos.write(b, 0, len);}baos.flush();byte[] bytes = baos.toByteArray();gifImageView.setBytes(bytes);//设置gif图片gifImageView.startAnimation();//运行动画} catch (IOException e) {// TODO Auto-generated catch block
e.printStackTrace();
}你需要将图片转为byte[]数组,然后再赋给GifImageView。最后调用gifImageView.startAnimation()让动画运行起来。
另外,官方提供了GifDataDownloader类,可让你下载远程的图片:
new GifDataDownloader() {
@Override
protected void onPostExecute(final byte[] bytes) {
gifImageView.setBytes(bytes);
gifImageView.startAnimation();
Log.d(TAG, "GIF width is " + gifImageView.getGifWidth());
Log.d(TAG, "GIF height is " + gifImageView.getGifHeight());
}}.execute("http://gifs.joelglovier.com/aha/aha.gif");demo下载http://download.csdn.net/detail/qq_35549248/9847667