我有一个textView,可以将其拖动到屏幕上的任何位置,但是拖动时它在屏幕外,因此如何仅在屏幕内拖动。
override fun onTouch(v: View?, event: MotionEvent?): Boolean {
val item = ClipData.Item(v!!.tag.toString())
val mimeTypes = arrayOf(ClipDescription.MIMETYPE_TEXT_PLAIN)
val data = ClipData(v.tag.toString(), mimeTypes, item)
val mShadow = View.DragShadowBuilder(v)
when (v.id) {
R.id.wordTV ->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
v.startDragAndDrop(data, mShadow, v, DRAG_FLAG_OPAQUE)
} else {
v.startDrag(data, mShadow, v, DRAG_FLAG_OPAQUE)
}
}
return false
}