Skip to content

Instantly share code, notes, and snippets.

@emedinaa
Created April 26, 2019 14:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save emedinaa/135f89d288ba64db0fe21951b396c58c to your computer and use it in GitHub Desktop.
Save emedinaa/135f89d288ba64db0fe21951b396c58c to your computer and use it in GitHub Desktop.
Kotlin OnTouchListener
package com.emedinaa.kotlin
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.MotionEvent
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
var pDownX=0
var pDownY=0
var pUpX=0
var pUpY=0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
/*imageView.setOnTouchListener(object:View.OnTouchListener{
override fun onTouch(v: View?, event: MotionEvent?): Boolean {
return true
}
})*/
imageView.setOnTouchListener { v, event ->
val action = event.action
when(action){
MotionEvent.ACTION_DOWN -> {
pDownX= event.x.toInt()
pDownY= event.y.toInt()
}
MotionEvent.ACTION_MOVE -> { }
MotionEvent.ACTION_UP -> {
pUpX= event.x.toInt()
pUpY= event.y.toInt()
}
MotionEvent.ACTION_CANCEL -> {
}
else ->{
}
}
true
}
}
}
@blu3crab
Copy link

very nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment