Created
April 26, 2019 14:43
-
-
Save emedinaa/135f89d288ba64db0fe21951b396c58c to your computer and use it in GitHub Desktop.
Kotlin OnTouchListener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very nice!