2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Glideについて

Posted at

Glideとは

Android用の画像読み込みライブラリになります。

機能面でいうと
・基本的に画像URLと表示するImageViewを指定するだけ
・メモリキャッシュ、ファイルキャッシュを自動に行ってくれる
・Gifアニメーションが表示できる

準備

インポートからします
app/build.gradleに以下を書きこむ

app/build.gradle
dependencies {
    //Glide
    def glide_version = '4.9.0'
    implementation "com.github.bumptech.glide:glide:$glide_version"
    annotationProcessor "com.github.bumptech.glide:compiler:$glide_version"
}

実装

最低限必要なコードがいかになります。
画像URLをImageViewに入れる感じになります。

sample.kt
Glide.with(itemView)
    //以下で画像のURLをStringで渡す
     .load("画像URL")
   //配置するImageViewを指定
     .into(imageView)

オプションコード(その他機能)

sample.kt
Glide.with(itemView)
     //角丸に 
     .apply(RequestOptions.bitmapTransform(RoundedCorners(30)))
     //大きさを指定
     .override(300, 300)

終わりに

自分が行なっていて詰まった点は画像は読み取れるのに表示されないことでした。
原因として、XMLで置いたパーツが他のパーツに潰されて隠れていました。
コードには問題なくも、パーツの設定とかで見えなくなってしまう可能性もあるのでもし、表示されなかったらその辺もみてみるいいかと思います。

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?