Fresco: ¿Cómo configurar loopcount para AnimatedImage después de v1.4.0?

Creado en 11 ago. 2017  ·  4Comentarios  ·  Fuente: facebook/fresco

Ahora mi objetivo es reproducir una imagen gif 5 veces.
Y encontré que hay un método getLoopCount para obtener el número de bucles de una imagen animada,
pero la pregunta es que no sé cómo establecer de forma dinámica loopCount.
Esperando tu ayuda.

question

Comentario más útil

Idealmente, su GIF estaría formateado correctamente y tendría el recuento de bucles establecido en N.

De lo contrario, puede crear un backend de modificación, algo como esto:

public class LoopCountModifyingBackend extends AnimationBackendDelegate {

  private int mLoopCount;

  public LoopCountModifyingBackend(
      <strong i="7">@Nullable</strong> AnimationBackend animationBackend,
      int loopCount) {
    super(animationBackend);
    mLoopCount = loopCount;
  }

  <strong i="8">@Override</strong>
  public int getLoopCount() {
    return mLoopCount;
  }
}

y luego configúrelo en su dibujo animado:

final DraweeController controller = Fresco.newDraweeControllerBuilder()
    .setAutoPlayAnimations(true)
    .setUri(uri)
    .setControllerListener(new BaseControllerListener<ImageInfo>() {
      <strong i="12">@Override</strong>
      public void onFinalImageSet(
          String id,
          <strong i="13">@Nullable</strong> ImageInfo imageInfo,
          <strong i="14">@Nullable</strong> Animatable animatable) {
        if (animatable instanceof AnimatedDrawable2) {
          AnimatedDrawable2 animatedDrawable = (AnimatedDrawable2) animatable;
          animatedDrawable.setAnimationBackend(new LoopCountModifyingBackend(animatedDrawable.getAnimationBackend(), 3));
        }
      }
    })
    .build();
simpleDraweeView.setController(controller);

También puede crear un DrawableFactory personalizado que haga esto directamente y luego pasarlo cuando la imagen se procesa a través de PipelineDraweeController.

Todos 4 comentarios

Idealmente, su GIF estaría formateado correctamente y tendría el recuento de bucles establecido en N.

De lo contrario, puede crear un backend de modificación, algo como esto:

public class LoopCountModifyingBackend extends AnimationBackendDelegate {

  private int mLoopCount;

  public LoopCountModifyingBackend(
      <strong i="7">@Nullable</strong> AnimationBackend animationBackend,
      int loopCount) {
    super(animationBackend);
    mLoopCount = loopCount;
  }

  <strong i="8">@Override</strong>
  public int getLoopCount() {
    return mLoopCount;
  }
}

y luego configúrelo en su dibujo animado:

final DraweeController controller = Fresco.newDraweeControllerBuilder()
    .setAutoPlayAnimations(true)
    .setUri(uri)
    .setControllerListener(new BaseControllerListener<ImageInfo>() {
      <strong i="12">@Override</strong>
      public void onFinalImageSet(
          String id,
          <strong i="13">@Nullable</strong> ImageInfo imageInfo,
          <strong i="14">@Nullable</strong> Animatable animatable) {
        if (animatable instanceof AnimatedDrawable2) {
          AnimatedDrawable2 animatedDrawable = (AnimatedDrawable2) animatable;
          animatedDrawable.setAnimationBackend(new LoopCountModifyingBackend(animatedDrawable.getAnimationBackend(), 3));
        }
      }
    })
    .build();
simpleDraweeView.setController(controller);

También puede crear un DrawableFactory personalizado que haga esto directamente y luego pasarlo cuando la imagen se procesa a través de PipelineDraweeController.

Gracias.

ahora para fresco 2.0.0+, ¿cómo hacer esto?

funciona muy bien!

¿Fue útil esta página
0 / 5 - 0 calificaciones