Edit:
Your question is asking two thing.
One is about OnLongClickListener
and I answered below by original answer.
And the other is about displaying gif, and you need to use image library, named Glide
.
Read this:
https://stackoverflow.com/a/44493206/850347
First, add this code to your app/build.gradle
repositories {
mavenCentral()
google()
}
dependencies {
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
}
And then, sync your gradle. After you edit build.gradle
file, you can see notice bar (top of the screen).
Next, add this code to your kotlin file. Change R.raw.image_gif
to your gif file name.
Glide.with(this).asGif().load(R.raw.image_gif).into(walk1);
Original:
You are setting LongClickListener
on walk1
, and ClickListener
on walk2
.
In this case, you need to focus on the return value of the LongClickListener
.
Almost every method associated with event, return true
means "I want to consume event and don't want it propagated. This point is end of the event." return false
means "I just want to process my event, and the event will propagate to it's parent view (or child view)"
Last line of kotlin method (which needs return) means "return". So in this code, false
is equivalent to return false
.
val walk1: ImageView = findViewById(R.id.walky)
val walk2: ImageView = findViewById(R.id.walky1)
walk1.setOnLongClickListener {
walk2.visibility = View.VISIBLE
false // Don't consume event, if return false. Consume event if true.
}
walk2.setOnClickListener {
walk2.visibility = View.GONE
}