GifImageView 和 GifDrawable的配合使用:
- 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实例画在了画布上。