val mImageView = findViewById<ImageView>(R.id.image_view_1) val mButton = findViewById<Button>(R.id.button_1) val tv1 = findViewById<View>(R.id.textView) val tv2 = findViewById<View>(R.id.textView2) val currentDisplay = windowManager.currentWindowMetrics val dw = currentDisplay.bounds.width() val dh = currentDisplay.bounds.height() val mBitmap = Bitmap.createBitmap(dw, dh, Bitmap.Config.ARGB_8888) val mCanvas = Canvas(mBitmap) mImageView.setImageBitmap(mBitmap) mButton.setOnClickListener { val mPaint = Paint() mPaint.color = Color.GREEN mPaint.style = Paint.Style.STROKE mPaint.strokeWidth = 10F mPaint.isAntiAlias = true val mStartX = tv1.bottom.toFloat() val mStartY = tv1.left.toFloat() val mStopX = tv2.top.toFloat() val mStopY = tv2.right.toFloat() mCanvas.drawLine(mStartX, mStartY, mStopX, mStopY, mPaint) mImageView.setImageBitmap(mBitmap) }
còn đây là hình code chạy