Android開発爆笑記

レセプターのソフト&ハード開発備忘録

ImageViewでGifアニメーションを表示 2021.09現在

ImageViewでGifアニメーションを表示は、デフォルトでは出来なかった。

「画像ライブラリGlide」を使うと華麗、綺麗、簡単にImageViewにGifを表示できるとあったので備忘録

 

gradle(:app)にライブラリインポートを2行追加

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

annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

 

◆gifアニメのファイルを格納

rawフォルダを作る

res/rawにファイルをコピーして格納

 

◆ImageViewをレイアウト.xmlに準備

 <ImageView
            android:id="@+id/gifanime"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

 

◆Activityで指定

ImageView imageView = (ImageView) findViewById(R.id.gifanime);
Glide.with(this).load(R.raw.ファイル名).into(imageView);

 

実行すると表示でアニメしていた。

f:id:receptorinc:20210902172558g:plain

Gifは引用しないでね