我试图在将imageview保持一定的持续时间(长按)后启用拖放的imageview。
因此,拖放工作正常(onTouch ACTION_DOWN
/ ACTION_MOVE
/ ACTION_UP
),但是这使我无法检测到View.OnLongClick
。当我删除onTouch
时,OnLongClick
被成功检测到。
如何使这两个听众并排工作?
onCreate:
{
editPhoto1.setOnTouchListener(this)
editPhoto2.setOnTouchListener(this)
editPhoto3.setOnTouchListener(this)
editPhoto1.isLongClickable = true
editPhoto2.isLongClickable = true
editPhoto3.isLongClickable = true
editPhoto1.setOnLongClickListener(this)
editPhoto2.setOnLongClickListener(this)
editPhoto3.setOnLongClickListener(this)
}
onLongClick
override fun onLongClick(v: View?): Boolean {
Log.d(TAG, "LongClick") // doesn't fire
when (v){
is CircleImageView -> {
v.elevation = 20f
v.borderColor = ContextCompat.getColor(this, R.color.colorPrimary)
ready = true
}
}
return true
}
onTouch
override fun onTouch(v: View?, event: MotionEvent?): Boolean {
if (v is CircleImageView){
when (event?.action){
ACTION_DOWN -> {
v.alpha = 0.7f
}
ACTION_MOVE -> {
if (!ready) return false
...
}
return true
}
有什么主意吗?
答案 0 :(得分:2)
因为该事件已经被onTouch占用了,所以从理论上讲, 如果您可以通过触摸返回false(长时间不消耗),则应该可以使用