GIFImageView

GifImageView 和 GifDrawable的配合使用:

  1. GifDrawble是继承了Animatable接口的,系统会在特定时刻调用其中的start,开启渲染任务。
    2.渲染任务开启后,GifDrawble中的GifInfoHandle定时渲染GifDrawble的bitmap实例。
    3.完成一次bitmap的渲染后,会调用Drawable对象的invalidateSelf方法。

/**

  • Use the current {@link Callback} implementation to have this Drawable
  • redrawn. Does nothing if there is no Callback attached to the
  • Drawable.
  • @see Callback#invalidateDrawable
  • @see #getCallback()
  • @see #setCallback(android.graphics.drawable.Drawable.Callback)
    */
    public void invalidateSelf() {
    final Callback callback = getCallback();
    if (callback != null) {
    callback.invalidateDrawable(this);
    }
    }

public interface Callback {
/**

/**
   * Called when the drawable needs to be redrawn.  A view at this point
 * should invalidate itself (or at least the part of itself where the
 * drawable appears).
 *
 * @param who The drawable that is requesting the update.
 */
void invalidateDrawable(@NonNull Drawable who);
 * A Drawable can call this to schedule the next frame of its
 * animation.  An implementation can generally simply call
 * {@link android.os.Handler#postAtTime(Runnable, Object, long)} with
 * the parameters <var>(what, who, when)</var> to perform the
 * scheduling.
 *
 * @param who The drawable being scheduled.
 * @param what The action to execute.
 * @param when The time (in milliseconds) to run.  The timebase is
 *             {@link android.os.SystemClock#uptimeMillis}
 */
void scheduleDrawable(@NonNull Drawable who, @NonNull Runnable what, long when);

/**
 * A Drawable can call this to unschedule an action previously
 * scheduled with {@link #scheduleDrawable}.  An implementation can
 * generally simply call
 * {@link android.os.Handler#removeCallbacks(Runnable, Object)} with
 * the parameters <var>(what, who)</var> to unschedule the drawable.
 *
 * @param who The drawable being unscheduled.
 * @param what The action being unscheduled.
 */
void unscheduleDrawable(@NonNull Drawable who, @NonNull Runnable what);

}

4.ImageView是设置了这个CallBack的,并且在invalidateDrawable回掉中调用了invalidate方法。
5.ImageView在onDraw方法中调用drawable的draw 方法,GifDrawable的draw方法把GifDrawable包含的bitmap实例画在了画布上。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值