Create your account

Already have an account? Login here

Note: By joining, you will receive periodic emails from Coursetro. You can unsubscribe from these emails.

Create account

94. Detect Compound Drawable Clicks

Design + Code an Android App from Scratch

Woah, wait a second..

Scrounge up some loose change to become a pro member, or login to your account to view this lesson.

Alright, join now. Or login to your account if you're already a pro member.

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.

Course Cirriculum