如何从url在android中玩gif?

use*_*902 13 android animated-gif

我想在Android应用程序中像urgur app一样从url播放动画gif.Imagur非常棒,非常快.我正在使用webview加载gif,但它没有达到标记.

Ang*_*i H 13

你可以使用Glide来玩gif ImageView.所以,让我们将它添加到你的应用程序的gradle中:

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.github.bumptech.glide:glide:3.6.1'
    compile 'com.android.support:support-v4:23.1.1'
}
Run Code Online (Sandbox Code Playgroud)

然后,创建一个ImageView:

<ImageView
    android:id="@+id/imageView"
    android:contentDescription="@string/content"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
Run Code Online (Sandbox Code Playgroud)

在您的活动中:

Glide  
    .with(context) // replace with 'this' if it's in activity
    .load("http://www.google.com/.../image.gif")
    .asGif()
    .error(R.drawable.error_image) // show error drawable if the image is not a gif
    .into(R.id.imageView);
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请打开此文章Glide - 显示GIF和视频.

  • 这需要时间,因为它首先被下载到缓存中。如果您想要快速输出,请将其打包在资产文件夹中的 apk 中并从那里访问它。 (2认同)

小智 0

您可以将 imageview 设置为:

           <com.example.androidgif.GifView
            android:id="@+id/gifview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
Run Code Online (Sandbox Code Playgroud)

按照本教程您可以做到:

http://android-er.blogspot.de/2014/03/load-animated-gif-from-internet.html