glide4 加载动画gif,textview设置顶部图动画

package com.android.launcher3.utils;

import android.content.Context;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.widget.TextView;


import com.bumptech.glide.load.resource.gif.GifDrawable;
import com.bumptech.glide.request.target.CustomViewTarget;
import com.bumptech.glide.request.transition.Transition;



public class TextViewDrawableTarget extends CustomViewTarget<TextView, Drawable> {
    /**
     * Constructor that defaults {@code waitForLayout} to {@code false}.
     *
     * @param view
     */

    int wh;

    public TextViewDrawableTarget(@NonNull TextView view, int wh) {

        super(view);
        this.wh = wh;
    }

    @Override
    protected void onResourceCleared(@Nullable Drawable placeholder) {

    }

    @Override
    public void onLoadFailed(@Nullable Drawable errorDrawable) {
        //加载失败例如url=null,此时使用 fallback不生效
        // view.setCompoundDrawablesWithIntrinsicBounds(null, mContext.getDrawable(R.mipmap.ic_boy), null, null);
    }

    @Override
    public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
        resource.setBounds(0, 0, wh, wh);

        //view.setCompoundDrawablesWithIntrinsicBounds(null,resource, null, null);
        view.setCompoundDrawables(null, resource, null, null);

        if (resource instanceof GifDrawable) {
            ((GifDrawable) resource).start();
        } else if (resource instanceof Animatable) {
            ((Animatable) resource).start();
        }


    }




}

使用
/**
 * 加载圆角图片gif
 */
public static void loadRoundCircleImageGif(Context context, String url, TextView view, int wh) {
    RequestOptions options = new RequestOptions()
            .centerCrop()
            .circleCrop()//设置圆形
            .placeholder(placeholderSoWhite)
            .error(errorSoWhite)
            //.priority(Priority.HIGH)
            .bitmapTransform(new RoundedCornersTransformation(25, 0, RoundedCornersTransformation.CornerType.ALL))
            .diskCacheStrategy(DiskCacheStrategy.ALL);
    Glide.with(context).load(url).apply(options).into(new TextViewDrawableTarget(view, wh));

}
Glide 是一个高效、开源、 Android设备上的媒体管理框架,它遵循BSD、MIT以及Apache 2.0协议发布。Glide具有加载本地片、远程片、GIF动画等功能。项目地址:https://github.com/bumptech/glide 你也可以直接下载jar包:https://github.com/bumptech/glide/releases 如何使用:创建个ImageView2. 获取片并填充到ImageView  获取远程片: Glide.with(this).load("http://www.see-source.com/source/img/logo_01.png").into(iv);   获取本地片:Glide.with(this).load(R.drawable.logo_01).into(iv);  获取GIF动画Glide.with(this).load(R.drawable.image02).into(iv);image02.gif是个动画片具体功能如下:GIF 动画的解码 :通过调用Glide.with(context).load(“片路径“)方法,GIF动画片可以自动显示为动画效果。如果想有更多的控制,还可以使用Glide.with(context).load(“片路径“).asBitmap()方法加载静态片,使用Glide.with(context).load(“片路径“).asGif()方法加载动画片本地视频剧照的解码: 通过调用Glide.with(context).load(“片路径“)方法,Glide能够支持Android设备中的所有视频剧照的加载和展示缩略的支持: 为了减少在同一个view组件里同时加载多张片的时间,可以调用Glide.with(context).load(“片路径“).thumbnail(“缩略比例“).into(“view组件“)方法加载一个缩略,还可以控制thumbnail()中的参数的大小,以控制显示不同比例大小的缩略Activity 生命周期的集成: 当Activity暂停和重启时,Glide能够做到智能的暂停和重新开始请求,并且当Android设备的连接状态变化时,所有失败的请求能够自动重新请求转码的支持: Glide的toBytes() 和transcode() 两个方法可以用来获取、解码和变换背景片,并且transcode() 方法还能够改变片的样式动画的支持: 新增支持片的淡入淡出动画效果(调用crossFade()方法)和查看动画的属性的功能OkHttp 和Volley 的支持: 默认选择HttpUrlConnection作为网络协议栈,还可以选择OkHttp和Volley作为网络协议栈其他功能: 如在加载过程中,使用Drawables对象作为占位符、片请求的优化、片的宽度和高度可重新设定、缩略和原的缓存等功能
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值