El Arsenal de Android – Animaciones

Primero debes saber qué es lotte?

Lottie carga y renderiza animaciones y vectores exportados al formato JSON bodymovin. Bodymovin JSON se puede crear y exportar desde After Effects con bodymovin, Sketch con Lottie Sketch Export y desde Haiku.

Por primera vez, los diseñadores pueden crear y enviar hermosas animaciones sin que un ingeniero las vuelva a crear cuidadosamente a mano. Dado que la animación es compatible con JSON, son de tamaño extremadamente pequeño pero pueden ser de gran complejidad.

¡COMENZEMOS! ?

Instalar AXrLottie

Primer paso, debe instalar AXrLottie

Uso básico

Cree un AXrLottieImageView en su diseño.

  < com  .aghajari.rlottie. AXrLottieImageView
         android :  id  =   " @ + id / lotse_view " 
          android :  layout_width  = [19659008] " 180dp " 
          android :  layout_height  =   " 180dp " 
          android :  layout_gravity  =   " center "   /> 

Ahora solo tiene que cargar su lote de animación

  batchView .  setLottieDrawable ( AXrLottieDrawable .  fromAssets ( este  fileName)
                .setSize (ancho, alto)
                .construir());
Lotes and View .  playAnimation (); 

puede cargar el archivo por lotes de las siguientes fuentes:

  • Archivo
  • Json (String)
  • Url
  • Activos
  • Recurso
  • InputStram

por lotes y almacenará en caché animaciones y archivos que es posible deshabilitar la caché en AXrLottieDrawable Builder

Salida

LayerProperty

  lote y Vista .  setLayerProperty (  " layer_name. ** "   AXrLottieProperty .  colorProperty (color)); 

Propiedades:

  • Color
  • FillOpacity
  • StrokeOpacity
  • StrokeWidth
  • Stroke 19659041] TrOpacity
  • TrPosition
  • TrRotation
  • TrScale

Salida [19459000397

AnimationLayers

  para  ( AXrayerLotti1990 layerInfo :  lotes y dibujables .  getLayers ()) {
     Log .  i (  " AXrLottie "    " layerName: "    +  layerInfo .  ] getName ());
} 

Lottie2Gif

¡puede exportar animaciones por lotes como GIF! gracias a gif-h

   AXrLottie2Gif .  crear (lotes y dibujables)
                .setListener ( nuevo    AXrLottie2Gif .  Lottie2GifListener  () {
                     inicio prolongado ;

                     @Override 
                      public    void    onStarted  () {
                        inicio  =    Sistema .  currentTimeMillis ();
                    }

                     @Override 
                      public    void    onProgress  ( int    frame  int    totalFrame ) {
                        log (  " progreso: "    +  frame  +    " / "    +  totalFrame);
                    }

                     @Override 
                      público    void    enFinished  () {
                        log (  " GIF creado ("    +  ( Sistema .  currentTimeMillis ()  -  inicio)  +    " ms)   r  n "    + 
                                  " Resolución: "    +  gifSize  +    " x "    +  gifSize  +    "   r  n "    + 
                                  " Ruta: "    +  archivo .  getAbsolutePath ()  +    "   r  n "    + 
                                  " Tamaño de archivo: "    +  (archivo .  longitud ()  /    1024 )  +    " kb " );
                    }
                })
                .setBackgroundColor ( Color .  BLANCO )
                .setOutputPath (archivo)
                .setSize (gifSize, gifSize)
                .setBackgroundTask ( true )
                .setDithering ( falso )
                .setDestroyable ( verdadero )
                .construir (); 

Salida

Listeners

OnFrameChangedListener:

   void  onFrameChanged ( AXrLottieDrawable  drawable19,  frame: 1965369031L ]  void  onUpdate ( AXrLottieDrawable  dibujable,  int  frame,  long  timeDiff  force);
 Mapa de bits  renderFrame ( AXrLottieDrawable  dibujable,  Mapa de bits  mapa de bits,  int  marco); 

AnimatedSticker – AXE005] YouView puede crear AXrLottieImageView en AXEmojiView / StickerView usando este código:

   AXEmojiManager .  setStickerViewCreatorListener ( nuevo    StickerViewCreatorListener  () {
     @Override 
      público    Ver    enCreateStickerView  ( @NonNull    Context    context  @Nullable    StickerCategory    categoría  booleano    isRecent ) {
         volver    nuevo    AXrLottieImageView  (contexto);
    }
    
     @Override 
      público    Ver    enCreateCategoryView  ( @NonNull    Context    context ) {
         volver    nuevo    AXrLottieImageView  (contexto);
    }
}); 

agréguelo justo después de AXEmojiManager.install

y podrá cargar sus animaciones en StickerProvider

   @Override 
      public    StickerLoader  getLoader () {
         volver    nuevo    StickerLoader  () {
             @Override 
              public    void    onLoadSticker  ( Ver    ver   Adhesivo    adhesivo ) {
                 if  (ver  instancia de    AXrLottieImageView    &&  pegatina  instancia de    AnimatedSticker ) {
                     AXrLottieImageView  lotes yImageView  =  ( AXrLottieImageView ) vista;
                     AnimatedSticker  animatedSticker  =  ( AnimatedSticker ) pegatina;
                     if  (animatedSticker .  drawable  ==   null ) {
                        animatedSticker .  dibujable  =    Utils .  createFromSticker (ver .  getContext (), animatedSticker,  100 );
                    }
                    lotes e ImageView .  setLottieDrawable (animatedSticker .  dibujable);
                    lotes e ImageView .  playAnimation ();
                }
            }

             @Override 
              public    void    onLoadStickerCategory  ( Ver    ver   StickerCategory    stickerCategory  [1945903119659084] seleccionado) {19459019] seleccionado
                 si  (ver  instancia de    AXrLottieImageView ) {
                     AXrLottieImageView  lotes yImageView  =  ( AXrLottieImageView ) vista;
                     AnimatedSticker  animatedSticker  =  ( AnimatedSticker ) stickerCategory .  getCategoryData ();
                     if  (animatedSticker .  drawable  ==   null ) {
                        animatedSticker .  dibujable  =    Utils .  createFromSticker (ver .  getContext (), animatedSticker,  50 );
                    }
                    lotes e ImageView .  setLottieDrawable (animatedSticker .  dibujable);
                      //  lotes e ImageView.playAnimation (); 
                }
            }
        };
    } 

Salida

Autor

Samsung / rlottie

  Copyright 2020 Amir Hossein Aghajari
Con licencia de Apache License, Versión 2.0 (la "Licencia");
no puede utilizar este archivo excepto de acuerdo con la licencia.
Puede obtener una copia de la licencia en

   http://www.apache.org/licenses/LICENSE-2.0

A menos que lo exija la ley aplicable o se acuerde por escrito, el software
distribuido bajo la Licencia se distribuye "TAL CUAL",
SIN GARANTÍAS NI CONDICIONES DE NINGÚN TIPO, ya sea expresa o implícita.
Consulte la licencia para el idioma específico que rige los permisos e
limitaciones de la licencia.

.

Compruebe también

Blog para desarrolladores de Android: Lucha contra las estafas de robo de identidad: el enfoque innovador de Monzo

Publicado por Todd Burner, ingeniero de relaciones con desarrolladores Los ciberdelincuentes continúan invirtiendo en estafas …

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *