如何在Android应用程序中显示动画GIF图像?

ama*_*pid 29 user-interface android

我想在Android应用程序中显示动画GIF图像,如下图所示.我尝试过webview但没有成功.如何在应用程序中显示动画gif?在此输入图像描述

Ryu*_*uZz 29

您还可以使用此lib轻松支持gifDrawable.

只需使用GifImageView而不是普通的ImageView:

<pl.droidsonroids.gif.GifImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/your_anim"/>
Run Code Online (Sandbox Code Playgroud)

并在src attr下找到你的gif文件.就这样!

  • 这不是重复动画,你告诉我该怎么做 (2认同)
  • @warlock你的gif文件应该自动重复你不能以编程方式执行此操作.在Photoshop中你可以这样做:"文件>保存为Web和设备",你可以设置循环选项 (2认同)

mle*_*kiy 18

你可以使用Glide:

ImageView imageView = (ImageView) findViewById(R.id.imageView);
GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView);
Glide.with(this).load(R.raw.sample_gif).into(imageViewTarget);
Run Code Online (Sandbox Code Playgroud)


ama*_*pid 8

经过长时间的谷歌搜索,我知道GIF图像没有原生支持.在应用程序中显示动画gif没有适当的解决方案.您可以查看此解决方案

在布局中制作动画gif.


Dee*_*pta 5

我尝试了很多库来使用 Animated gif 。但每个图书馆都落后且不堪重负。但现在,经过一两天的研究,我有了一个使用动画 gif 的想法,并且性能非常好,没有滞后,没有压垮。

解决方案是使用Glide

请按照以下步骤操作。

在 xml 文件中。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#62b849"
    tools:context=".MainActivity">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:id="@+id/splace_image_view"
        android:layout_centerInParent="true"/>

</RelativeLayout> 
Run Code Online (Sandbox Code Playgroud)

并在你的java文件中

 ImageView imageView = findViewById(R.id.splace_image_view);

Glide
        .with(this)
        .load(R.drawable.football)
        .into(imageView);
Run Code Online (Sandbox Code Playgroud)