LoginSignup
45
42

More than 5 years have passed since last update.

AndroidのViewでGIF動画を表示する

Last updated at Posted at 2016-05-19

Gif動画表示したいな

AndroidのImageViewでGif動画を表示したい。
ぐぐってみると、カスタムビューを作ろう、Movieクラスを使用する!

等色々大変そう。。。

神ライブラリGlide

なんと画像ライブラリGlideを使うと華麗、綺麗、簡単にImageViewにGifを表示できちゃうのだ。

やってみよう

依存関係

build.gradle
dependencies {
        compile 'com.github.bumptech.glide:glide:3.6.1'
}

gifをプロジェクトに入れとこう

gifを入れる場所は

res/raw

です。

View を用意

activity_main.xml
    <ImageView
            android:id="@+id/gifView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

バインディングしちゃおう

MainActivity.java
ImageView imageView = (ImageView) findViewById(R.id.gifView);
        GlideDrawableImageViewTarget target = new GlideDrawableImageViewTarget(imageView);
        Glide.with(this).load(R.raw.lane).into(target);

完成

device-2016-05-19-133805.mp4.gif

45
42
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
45
42