加载gif动图

现在在做一个项目,要加载gif动图,查找了好多关于这方面的知识,终于解决了,为了下次能用的上,也为了能够帮助其他人,写下这篇博客。

  • 布局代码如下:
<RelativeLayout
            android:id="@+id/img_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:background="#FFF"
            android:visibility="visible">

            <ImageView
                android:id="@+id/iv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:contentDescription="@null"
                android:scaleType="centerCrop" />

            <ImageView
                android:id="@+id/iv_gif"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:contentDescription="@null"
                android:src="@drawable/ic_play_gif"
                android:visibility="gone" />
        </RelativeLayout>

这里写图片描述

  • 接下来就看看MainActivity中的代码了:
public class MainActivity extends Activity {
   

    private ImageView iv;
    private ImageView ivGif;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        iv = (ImageView) findViewById(R.id.iv);
        ivGif= (ImageView) findViewById(R.id.ivGif);
        //初始化volley
        ImageLoadProxy.initImageLoader(this);
        if (url.endsWith(".gif")) {
            ivGif.setVisibility(View.VISIBLE);
        } else {
            ivGif.setVisibility(View.GONE);
        }
        ImageLoadProxy.displayImage4Detail(url, iv, new SimpleImageLoadingListener(){
            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                super.onLoadingComplete(imageUri, view, loadedImage);
            //这里可以隐藏进度条哦
            }
        },
        new ImageLoadingProgressListener() {
            @Override
            public void onProgressUpdate(String imageUri, View view, int current, int total) {
            //可以显示进度条哦
        
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值