I keep getting top, bottom, left, right = 0. I guess I am doing this wrong, what is the correct way? TIA
in onCreate()
ImageView trash = (ImageView) findViewById(R.id.dropTarget_trash);
trash.setOnTouchListener(this);
Rect trashHit = new Rect();
trash.getHitRect(trashHit);
Log.d(TAG,"Trash left:" + trashHit.left + " right: " + trashHit.right + " top: " + trashHit.top + " bottom: " + trashHit.bottom);
As the hit rect is in the parent coordinate space, the parent first needs to layout its children which it hasn't done yet during onCreate(). Take a look at the solution here for an example of running in post(). If you have a custom view, getHitRect() within onDraw() will give you the correct dimensions too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With