Hello All, By using simple onTouch event we make an DraggableTextView widget. Here is the code sample for you. override fun onTouch(v: View?, event: MotionEvent?): Boolean { val x = event?.rawX?.toInt()!! val y = event.rawY.toInt() when (event.action) { MotionEvent.ACTION_DOWN -> { val layoutParams = layoutParams as ConstraintLayout.LayoutParams xDelta = x - layoutParams.leftMargin yDelta = y - layoutParams.topMargin rect.set(0, 0, width, height) isDragging = true } MotionEvent.ACTION_MOVE -> { val layoutParams = layoutParams as ConstraintLayout.LayoutParams layoutParams.leftMargin = x - xDelta layoutParams.topMargin = y - yDelta setLayoutParams(layoutParams) } MotionEvent.ACTION_UP -> { isDragging = false } } invalidate() return true } Here is the full video tutorial. Interesting...
A plat with simple tutorial for native android developers.