I'm kinda trying to clone the ripple effect found in Google's material design. Now, I've noticed that the ripple always starts from the position that was touched. For this, I've created a drawable
which will be initially invisible and but will become visible once the view is touched. The ImageView
containing the drawable
will be then moved to the position that was touched and the ripple animation will start thereafter. Now, while trying to do this, I'm stumbling upon one thing which is I can't figure out how to find out the position that was touched. I came across several questions on stackoverflow which said that the touch position can be found out by using the following code.
@Override
public boolean onTouch(View v, MotionEvent e) {
int X = (int)(e.getX());
int Y = (int)(e.getY());
return false;
}
I did try to implement this code in my app but I ended up with a NullPointerException
. Please tell me how to find the exact location of the screen that was touched and move the view there?