加载gif(Android开源项目)

2019-02-21 11:27:09 浏览数 (1)

这是从网上下载下来并且重新运行通过了的代码。 目录结构如下:

使用时只需要把pl.droidsonroids.gif包和libs文件夹拷到相对应的位置,然后调用如下代码加载就行

代码语言:javascript复制
public class MainActivity extends Activity {
    /** 或者xml文件里面android:src="@drawable/pikachu" */
    private GifImageView gifImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        gifImageView = (GifImageView) findViewById(R.id.giv_demo);
        try {
            GifDrawable gifDrawable = new GifDrawable(getResources(),
                    R.drawable.pikachu);
            gifImageView.setImageDrawable(gifDrawable);
        } catch (NotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

代码地址:http://download.csdn.net/detail/lxj1137800599/9546848

gif

0 人点赞