Design + Code an Android App from Scratch
This video shows how to detect compound drawable clicks in Android. Our custom widget Bucket Date Picker View uses a complex layout comprised of three TextViews with compound drawables at the top and bottom to increment and decrement values inside each TextView respectively. We first discuss the difference between coordinates of the TextView and coordinates of the MotionEvent. We can get coordinates of the MotionEvent using getX, getY, or getRawX and getRawY. The coordinates of the TextView can be easily obtained using the getLeft, getRight, getTop and getBottom. We finally discuss the math behind detecting clicks for the top and bottom drawables after considering padding.