安卓原本是不支持动图的,我们需要通过第三方框架.
第一种,Glide网络加载框架,加载网络图片,本地图片都可以,代码如下:
compile 'com.github.bumptech.glide:glide:3.7.0' //引入glide
public void loadimage(ImageView view){
String url="http://p1.pstatp.com/large/166200019850062839d3"; //gif的url
int res= R.drawable.launcher; //本地gif图片
Glide.with(this).
load(res). //本地gif图片(加载网络图片就是load(url))
error(R.drawable.ic_launcher).
diskCacheStrategy(DiskCacheStrategy.NONE).
into(view);
}
第二种,GifView
compile 'com.github.Cutta:GifView:1.1'
<com.cunoraz.gifview.library.GifView
android:id="@+id/gif1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
custom:gif="@mipmap/gif1" />
GifView gifView1 = (GifView) view.findViewById(R.id.gif1);
gifView1.setVisibility(View.VISIBLE);
gifView1.play();
gifView1.pause();
gifView1.setGifResource(R.mipmap.gif5);
gifView1.getGifResource();
gifView1.setMovieTime(time);
gifView1.getMovie();