简体   繁体   English

在我的应用程序中加载 GIF 图像时遇到问题

[英]Having troubles loading a GIF image in my application

so i was trying to load a GIF image using a link into my application, but i couldn't find how.所以我试图使用链接将 GIF 图像加载到我的应用程序中,但我找不到方法。

i tried using Glide and Picasso but i still couldn't resolve my problem, at first i thought i might have something in my app that's stopping the GIF from loading so i tried creating a new app just to test loading a GIF in an app and still couldn't load a single GIF.我尝试使用 Glide 和 Picasso 但我仍然无法解决我的问题,起初我以为我的应用程序中可能有一些东西阻止了 GIF 加载所以我尝试创建一个新应用程序只是为了测试在应用程序中加载 GIF 和仍然无法加载单个 GIF。

I have looked around for a question like mine and tested some of the answers given but none of them worked!我环顾四周寻找像我这样的问题并测试了一些给出的答案,但没有一个有效!

so if anyone can show me a way to load a GIF in an app i would be quite thankful, and i can share the code for my app but as i stated earlier i am trying a new empty app and has no actual code in it.因此,如果有人能告诉我一种在应用程序中加载 GIF 的方法,我将非常感激,我可以分享我的应用程序的代码,但正如我之前所说,我正在尝试一个新的空应用程序并且其中没有实际代码。

There's too little information to know what happened.信息太少,无法知道发生了什么。 It would be better to show more detail about the code you tried and the result.最好显示有关您尝试的代码和结果的更多详细信息。

However, This is a Simple Example然而,这是一个简单的例子

AndroidManifest.xml : AndroidManifest.xml

add internet permission添加互联网权限

<uses-permission android:name="android.permission.INTERNET" />

build.gradle(:app) : build.gradle(:app)

add Glide Library.添加滑翔库。

implementation 'com.github.bumptech.glide:glide:4.12.0'

activity_main.xml : activity_main.xml

add an ImageView添加一个 ImageView

<ImageView
    android:id="@+id/imageView"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

MainActivity.kt: MainActivity.kt:

load GIF into imageView将 GIF 加载到 imageView

 val url = "https://media.giphy.com/media/3o7527pa7qs9kCG78A/giphy.gif"
 Glide.with(this)
     .load(url)
     .into(imageView)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM