Adding GIF file in an Android app

0
137

In this tutorial, In this blog, we will add GIF file that means Graphics Interchange Format in your android app. You can not have that type of file in your Android app by using ImageView or TextView. So here we will use a library to do so.

Output: –

Download Project – [media-downloader media_id=”882″]

Download APK – [media-downloader media_id=”884″]

Wants to Learn Advanced Android Application development from scratch- Beyond Basics

Creating New Project 

Open your Android Studio & create a new Project, we have taken Blank Activity for this project.We kept all the things by default and clicked finish.

Adding Dependencies in Gradle

You may see the Last line in our dependencies. To see the library we have included in this project.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.1.1'
    compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.+'
}

activity_main.xml

We have added a .gif file in our drawable folder named ‘running’.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.mytrendin.addinggif.MainActivity">

    <pl.droidsonroids.gif.GifTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:background="@drawable/running" />
</RelativeLayout>

Related:

Uploading file to Google Drive in Android Application

How to read PDF files in android

Play a music file in background using services

Downloading File From Android WebView

Android Pick File Programatically

MainActivity.java

package com.mytrendin.addinggif;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

If You are Beginner Learn Android application development from the scratch


If you really liked the article, please subscribe to our YouTube Channel for videos related to this article.Please find us on Twitter and Facebook.



LEAVE A REPLY

Please enter your comment!
Please enter your name here