Hmmm… U mnie działa.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ImageView
android:id="@+id/imageView"
android:layout_width="150dp"
android:layout_height="150dp"
/>
<Button
android:id="@+id/initButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="init"
/>
<Button
android:id="@+id/switchButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="switch"
/>
</LinearLayout>
class MainActivity : Activity() {
private val images = listOf(
"http://placehold.it/400x400&text=image1",
"http://placehold.it/400x400&text=image2",
"http://placehold.it/400x400&text=image3",
"http://placehold.it/400x400&text=image4",
"http://placehold.it/400x400&text=image5"
)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val imageView = findViewById<ImageView>(R.id.imageView)
val initButton = findViewById<Button>(R.id.initButton)
val switchButton = findViewById<Button>(R.id.switchButton)
Picasso.setSingletonInstance(Picasso.Builder(this).loggingEnabled(true).build())
initButton.setOnClickListener {
Log.d("LOG_TAG", "!!! ON CLICK INIT !!!")
Picasso.get()
.load("https://i.imgur.com/DvpvklR.png")
.fit()
.into(imageView)
for (image in images) {
Picasso.get()
.load(image)
.resize(imageView.width, imageView.height)
.fetch()
}
}
var counter = 0
switchButton.setOnClickListener {
Log.d("LOG_TAG", "!!! ON CLICK SWITCH !!!")
Picasso.get()
.load(images[counter])
.fit()
.into(imageView)
counter = (counter + 1) % images.size
}
}
}
D: !!! ON CLICK INIT !!!
D: Main created [R0] Request{https://i.imgur.com/DvpvklR.png resize(394,394)}
D: Main created [R1] Request{http://placehold.it/400x400&text=image1 resize(394,394)}
D: Main created [R2] Request{http://placehold.it/400x400&text=image2 resize(394,394)}
D: Main created [R3] Request{http://placehold.it/400x400&text=image3 resize(394,394)}
D: Dispatcher enqueued [R0]+3ms
D: Main created [R4] Request{http://placehold.it/400x400&text=image4 resize(394,394)}
D: Main created [R5] Request{http://placehold.it/400x400&text=image5 resize(394,394)}
D: Hunter executing [R0]+5ms
D: Dispatcher enqueued [R1]+4ms
D: Dispatcher enqueued [R2]+5ms
D: Dispatcher enqueued [R3]+6ms
D: Dispatcher enqueued [R4]+6ms
D: Dispatcher enqueued [R5]+5ms
D: Hunter executing [R1]+10ms
D: Hunter executing [R2]+12ms
D: Hunter decoded [R0]+237ms
D: Hunter transformed [R0]+238ms
D: Hunter executing [R3]+236ms
D: Dispatcher batched [R0]+238ms for completion
D: Hunter decoded [R1]+342ms
D: Hunter transformed [R1]+344ms
D: Hunter executing [R4]+343ms
D: Dispatcher batched [R1]+344ms for completion
D: Hunter decoded [R2]+345ms
D: Hunter transformed [R2]+350ms
D: Dispatcher batched [R2]+351ms for completion
D: Hunter executing [R5]+349ms
D: Dispatcher delivered [R0]+441ms, [R1]+439ms, [R2]+439ms
D: Main completed [R0]+441ms from NETWORK
D: Main completed [R1]+440ms from NETWORK
D: Main completed [R2]+439ms from NETWORK
D: Hunter decoded [R4]+502ms
D: Hunter transformed [R4]+504ms
D: Dispatcher batched [R4]+504ms for completion
D: Hunter decoded [R5]+508ms
D: Hunter transformed [R5]+510ms
D: Dispatcher batched [R5]+511ms for completion
D: Hunter decoded [R3]+555ms
D: Hunter transformed [R3]+556ms
D: Dispatcher batched [R3]+557ms for completion
D: Dispatcher delivered [R4]+706ms, [R5]+705ms, [R3]+706ms
D: Main completed [R4]+706ms from NETWORK
D: Main completed [R5]+705ms from NETWORK
D: Main completed [R3]+707ms from NETWORK
D: !!! ON CLICK SWITCH !!!
D: Main created [R6] Request{http://placehold.it/400x400&text=image1 resize(394,394)}
D: Main completed [R6] from MEMORY
D: !!! ON CLICK SWITCH !!!
D: Main created [R7] Request{http://placehold.it/400x400&text=image2 resize(394,394)}
D: Main completed [R7] from MEMORY
D: !!! ON CLICK SWITCH !!!
D: Main created [R8] Request{http://placehold.it/400x400&text=image3 resize(394,394)}
D: Main completed [R8] from MEMORY
D: !!! ON CLICK SWITCH !!!
D: Main created [R9] Request{http://placehold.it/400x400&text=image4 resize(394,394)}
D: Main completed [R9] from MEMORY
D: !!! ON CLICK SWITCH !!!
D: Main created [R10] Request{http://placehold.it/400x400&text=image5 resize(394,394)}
D: Main completed [R10] from MEMORY
D: !!! ON CLICK SWITCH !!!
D: Main created [R11] Request{http://placehold.it/400x400&text=image1 resize(394,394)}
D: Main completed [R11] from MEMORY