Skip to content

Instantly share code, notes, and snippets.

@ikhlaqmalik13
Created January 13, 2023 19:49
Show Gist options
  • Save ikhlaqmalik13/cde9c8758ffb766b0cbfd26c882faeaa to your computer and use it in GitHub Desktop.
Save ikhlaqmalik13/cde9c8758ffb766b0cbfd26c882faeaa to your computer and use it in GitHub Desktop.
Loading images using Glide and arraylist
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".learning.GlideActivity">
<androidx.core.widget.NestedScrollView
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<ImageView
android:scaleType="centerCrop"
android:id="@+id/iv_server_image"
android:layout_width="match_parent"
android:layout_height="@dimen/_320dp"
android:background="@color/black" />
<ImageView
android:scaleType="centerCrop"
android:id="@+id/iv_server_image2"
android:layout_width="match_parent"
android:layout_height="@dimen/_320dp"
android:background="@color/purple_500" />
<ImageView
android:scaleType="centerCrop"
android:id="@+id/iv_server_image3"
android:layout_width="match_parent"
android:layout_height="@dimen/_320dp"
android:background="@color/purple_500" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
package com.maple.kashin.learning
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.maple.kashin.databinding.ActivityGlideBinding
class Image(val imageUrl: String?, val ivServerImage: ImageView?) {}
class GlideActivity : AppCompatActivity() {
private lateinit var binding: ActivityGlideBinding
private var images: ArrayList<Image> = arrayListOf<Image>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityGlideBinding.inflate(layoutInflater)
setContentView(binding.root)
val img1 = Image(
"https://i.pinimg.com/564x/51/7c/af/517caf0d930f526896eb811b3869c31c.jpg",
binding.ivServerImage
)
val img2 = Image(
"https://i.pinimg.com/564x/44/3e/cb/443ecb7f724bc99256cec196a881cce1.jpg",
binding.ivServerImage2
)
val img3 = Image(
"https://i.pinimg.com/736x/1c/3b/41/1c3b41e00fb3efd6df810739af9e4b65.jpg",
binding.ivServerImage3
)
images.add(img1)
images.add(img2)
images.add(img3)
for (i in 0..2) {
Glide.with(this)
.load(images[i].imageUrl)
.into(images[i].ivServerImage!!)
}
}
}
//class Image(val imageUrl: String?, val ivServerImage: ImageView?) {
// var imageUrl : String? = null
// var view : ImageView? = null
//
// fun setUrl(url: String?){
// this.imageUrl = url
// }
//
// @JvmName("setView1")
// fun setView(iv : ImageView?){
// this.view = iv
// }
//
// fun setData(url: String?, iv : ImageView?){
// this.imageUrl = url
// this.view = iv
// }
//
// fun Image(url: String?, iv : ImageView?){
// this.imageUrl = url
// this.view = iv
// }
//}
/*
Glide.with(this)
.load("https://i.pinimg.com/564x/51/7c/af/517caf0d930f526896eb811b3869c31c.jpg")
.into(binding.ivServerImage)
Glide.with(this)
.load("https://i.pinimg.com/564x/44/3e/cb/443ecb7f724bc99256cec196a881cce1.jpg")
.into(binding.ivServerImage2)
Glide.with(this)
.load("https://i.pinimg.com/736x/1c/3b/41/1c3b41e00fb3efd6df810739af9e4b65.jpg")
.into(binding.ivServerImage3)
*/
//val img1 = Image("https://i.pinimg.com/564x/51/7c/af/517caf0d930f526896eb811b3869c31c.jpg", binding.ivServerImage)
//img1.setData("https://i.pinimg.com/564x/51/7c/af/517caf0d930f526896eb811b3869c31c.jpg", binding.ivServerImage )
// img1.setUrl("https://i.pinimg.com/564x/51/7c/af/517caf0d930f526896eb811b3869c31c.jpg")
// img1.setView(binding.ivServerImage)
// img1.imageUrl = "https://i.pinimg.com/564x/51/7c/af/517caf0d930f526896eb811b3869c31c.jpg"
// img1.view = binding.ivServerImage
// val img2 = Image(
// "https://i.pinimg.com/564x/44/3e/cb/443ecb7f724bc99256cec196a881cce1.jpg", binding.ivServerImage2
// )
//img2.setData("https://i.pinimg.com/564x/44/3e/cb/443ecb7f724bc99256cec196a881cce1.jpg", binding.ivServerImage2 )
// img2.setUrl("https://i.pinimg.com/564x/44/3e/cb/443ecb7f724bc99256cec196a881cce1.jpg")
// img2.setView(binding.ivServerImage2)
// img2.imageUrl = "https://i.pinimg.com/564x/44/3e/cb/443ecb7f724bc99256cec196a881cce1.jpg"
// img2.view = binding.ivServerImage2
// val img3 = Image(
// "https://i.pinimg.com/736x/1c/3b/41/1c3b41e00fb3efd6df810739af9e4b65.jpg",
// binding.ivServerImage3
// )
// img3.setData("https://i.pinimg.com/736x/1c/3b/41/1c3b41e00fb3efd6df810739af9e4b65.jpg", binding.ivServerImage3 )
// img3.setUrl("https://i.pinimg.com/736x/1c/3b/41/1c3b41e00fb3efd6df810739af9e4b65.jpg")
// img3.setView(binding.ivServerImage3)
// img3.imageUrl = "https://i.pinimg.com/736x/1c/3b/41/1c3b41e00fb3efd6df810739af9e4b65.jpg"
// img3.view = binding.ivServerImage3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment