Ripple effect on touched item

  Uncategorized

Google has started to use ripple animations in Material Design UIs. The setHotspot() method is added in API Level 21. This teaches the drawable a “hot spot”, and the RippleDrawable apparently uses this as the emanation point for the ripple effect. The setHotspot() method of a view take the x,y values from the MotionEvent to set the hot spot coordinates.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
  view.setOnTouchListener(new View.OnTouchListener() {
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    public boolean onTouch(View v, MotionEvent event) {
      v
        .findViewById(R.id.row_content)
        .getBackground()
        .setHotspot(event.getX(), event.getY());

      return(false);
    }
  });
}

Source: http://commonsware.com/