Android Display GIF Image Tutorial

GIF image format (Graphics Interchange Format) is an animated and static image on an application. Besides, It is lossless bitmap image and widely use over the world wide web. Android is able to support and display gif image in the application which can be very useful in specific situation. In this tutorial, I will teach you how to display the gif image in your application, you just need to follow my steps.

Creating a New Project

1. Open Android Studio IDE in your computer.
2. Create a new project and Edit the Application name to “GifExample”.
(Optional) You can edit the company domain or select the suitable location for current project tutorial. Then click next button to proceed.
3. Select Minimum SDK (API 15:Android 4.0.3 (IceCreamSandwich). I choose the API 15 because many android devices currently are support more than API 15. Click Next button.
4. Choose “Empty Activity” and Click Next button
5. Lastly, press finish button.

Sample GIF image

sample gif image

Add a GIF image in Project

Right click res > New > resource directory, make the directory name as “raw”. After that, copy the sample gif image and paste it to the “raw” directory.

Create a Class

Right click project name > New > Java Class and name it as “CustomGifView“.

Edit CustomGifView.java class

Copy and paste the following code to your customgifview.java. This class is to customize the view (gif file) to animation.

Edit activity_main.xml layout

Add and use custom view in your activity_main.xml, follow by your package name and class name. eg(com.example.questdot.gifexample.CustomGifView)

Edit AndroidManifest.xml

Add android:hardwareAccelerated=”false” in MainActivity, else you will get error when you run your project. Note: Hardware Accelerated cannot use it for drawing lines or curves and other trivial operations.

Run Your Project

Now, you can run your project and the application will successfully display the gif image in the screen.

(Android Display GIF Image)

Source Code

(Visited 299 times, 1 visits today)
Advertisements

Kristofer Ng

A crazy android and web developer. Passion on developing android application and exploring new technology as a hobby.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *