Sorry for the late posting. This time I will talk about how to play Gif images on Android.
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!
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" />
Specify ImageView where you want to paste the Gif image!
<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
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!
Set the gif image here
//When using a local gif image
ImageView matchImage = findViewById(R.id.image_view);
GlideDrawableImageViewTarget target = new GlideDrawableImageViewTarget(matchImage);
Glide.with(context).load(R.raw.gif).into(target);
//When using GIF images on the Internet
ImageView matchImage = findViewById(R.id.image_view);
String gifUrl = "https://~~~.gif";
Glide.with(this).load(gifUrl).into(matchImage);
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
resource.setLoopCount(1);
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.
```glidedrawableimageviewtarget(matchimage,1);```
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