How to increase the size of a current focused item on a RecyclerView?

Skycorsarius picture Skycorsarius · Oct 21, 2015 · Viewed 11.3k times · Source

I'm trying to make an horizontal list with a RecyclerView, that when I put the focus on an item, increase the size of this. I want to make this effect:

Increased item effect

Do you have any ideas to accomplish this?

Answer

Sebastiano picture Sebastiano · Oct 22, 2015

I'm imagining something like this:

  1. Create the horizontal RV
  2. When binding the ViewHolder, attach a FocusChangeListener to the root view of the item
  3. When the item gains focus, scale it to make it slightly bigger; when the focus is lost, revert the animation.

static class ViewHolder extends RecyclerView.ViewHolder {

  public ViewHolder(View root) {
    // bind views
    // ...

    // bind focus listener
    root.setOnFocusChangeListener(new View.OnFocusChangeListener() {
      @Override
        public void onFocusChange(View v, boolean hasFocus) {
          if (hasFocus) {
            // run scale animation and make it bigger
          } else {
            // run scale animation and make it smaller
          }
        }
     });
  }
}