I want to play a GIF image on the Andorid app (Java, Kotlin)

Sorry for the late posting. This time I will talk about how to play Gif images on Android.

Using the library

Andorid has several libraries for playing GIF images. Moreover, it is easy to use because it can be played in ImageView. This time, I will introduce one of the most popular libraries, glide!

1. Add glide to dependencies of build.gradle

Let's add the library first!

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

If you use images on the internet Add the following to Manifest.xml as well!

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

2. Add ImageView

Specify ImageView where you want to paste the Gif image!

    android:layout_height="match_parent" />

If you want to use the locally dropped Gif image instead of the URL Let's put the Gif image in drawable/raw!

3. Set the Gif image in ImageView

Set the gif image here

//When using a local gif image
ImageView matchImage = findViewById(R.id.image_view);
GlideDrawableImageViewTarget target = new GlideDrawableImageViewTarget(matchImage);

//When using GIF images on the Internet
ImageView matchImage = findViewById(R.id.image_view);
String gifUrl = "https://~~~.gif";

I want to stop continuous playback

In the initial state of this glide, the gif will continue to loop forever. So how do you stop this?

When I looked it up, it was a listener


 It was said that if you enter this, it will be played only once
 I couldn't even try it.

 But there is another good way, and I could change it like this!

ImageView matchImage = findViewById(R.id.image_view); GlideDrawableImageViewTarget target = new GlideDrawableImageViewTarget(matchImage,1); Glide.with(context).load(R.raw.gif).into(target);

 At first glance you may not know what has changed.
 1 is added here!
 The second argument here is the number of loops!
 So if you specify the second argument, you can specify the number of loops!

 This time is over! Until the end Thank you for reading!

Recommended Posts

I want to play a GIF image on the Andorid app (Java, Kotlin)
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
How to deploy a kotlin (java) app on AWS fargate
I want to implement it additionally while using kotlin on a site running Java
I want to create a chat screen for the Swift chat app!
I want to return to the previous screen with kotlin and java!
[Java] I want to calculate the difference from the date
I want to know the answer of the rock-paper-scissors app
I want to dark mode with the SWT app
I want to transition screens with kotlin and java!
I want to simplify the log output on Android
I want to add a delete function to the comment function
Rspec: I want to test the post-execution state when I set a method on subject
I want to go back to a specific VC by tapping the back button on the NavigationBar!
[Android Studio] I want to set restrictions on the values registered in EditText [Java]
I want to use screen sharing on the login screen on Ubuntu 18
How to deploy a simple Java Servlet app on Heroku
I want to call a method and count the number
I want to use the Java 8 DateTime API slowly (now)
I want to create a form to select the [Rails] category
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
I want to put the JDK on my Mac PC
I want to give a class name to the select attribute
I want to implement various functions with kotlin and java!
I want to simplify the conditional if-else statement in Java
[Ruby on Rails] I want to get the URL of the image saved in Active Storage
Create an Android app for those who don't want to play music on the speaker
Implemented a strong API for "I want to display ~~ on the screen" with simple CQRS
[Java] I tried to make a rock-paper-scissors game that beginners can run on the console.
I want to return a type different from the input element with Java8 StreamAPI reduce ()
I made a shopify app @java
I want to use swipeback on a screen that uses XLPagerTabStrip
I just want to write Java using Eclipse on my Mac
I want to add the disabled option to f.radio_button depending on the condition
[Java] I tried to make a maze by the digging method ♪
[Java] I want to perform distinct with the key in the object
I tried to display the calendar on the Eclipse console using Java.
I want to develop a web application!
I want to write a nice build.gradle
I want to make an ios.android app
I made an app to scribble with PencilKit on a PDF file
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (PowerMockito edition)
I want to write a unit test!
I want to download a file on the Internet using Ruby and save it locally (with caution)
I want to install PHP 7.2 on Ubuntu 20.04.
I want to create a dark web SNS with Jakarta EE 8 with Java 11
I made a rock-paper-scissors app with kotlin
Deploy a Java web app on Heroku
I made a calculator app on Android
I want to stop Java updates altogether
I want to get the IP address when connecting to Wi-Fi in Java
I want to ForEach an array with a Lambda expression in Java
I went to the Java Women's Club # 1
I want to get the field name of the [Java] field. (Old tale tone)
I tried to publish the reflex measurement application on the Google Play store
[Kotlin] I wanted to generate a png with a large capacity per area [Java]
Development memo ~ I want to display only the first image posted multiple times ~
I want you to use Scala as Better Java for the time being
Hello World, a cross-platform GUI app with Groovy running on the Java platform
[Azure] I tried to create a Java application for free-Web App creation- [Beginner]