title: How to scale down/up recycler view card item on click down/up in Android?
body: <p>I have a recycler view and inside that, every item is a card view.
  I want to scale down(size) the card item when I press the item and scale up when click up.</p>
  
  <p>following is <strong><em>CardViewActivity.java</em></strong></p>
  
  <pre><code>import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.LinearLayoutManager;
  import android.support.v7.widget.RecyclerView;
  import android.view.MotionEvent;
  import android.view.View;
  import android.widget.Toast;
  
  import java.util.ArrayList;
  
  public class CardViewActivity extends AppCompatActivity {
  
      private RecyclerView mRecyclerView;
      private RecyclerView.Adapter mAdapter;
      private RecyclerView.LayoutManager mLayoutManager;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_card_view);
  
          mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
          mRecyclerView.setHasFixedSize(true);
          mLayoutManager = new LinearLayoutManager(this);
          mRecyclerView.setLayoutManager(mLayoutManager);
          mAdapter = new MyRecyclerViewAdapter(getDataSet());
          mRecyclerView.setAdapter(mAdapter);
      }
  
  
      @Override
      protected void onResume() {
          super.onResume();
          ((MyRecyclerViewAdapter) mAdapter).setOnItemClickListener(new MyRecyclerViewAdapter
                  .MyClickListener() {
              @Override
              public void onItemClick(int position, View v) {
                  Toast.makeText(getApplicationContext(), " Clicked on Item " + position, Toast.LENGTH_SHORT).show();
              }
  
          });
  
          mRecyclerView.setOnTouchListener(new View.OnTouchListener() {
              @Override
              public boolean onTouch(View v, MotionEvent event) {
  
                  return false;
              }
          });
          mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
              @Override
              public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
                  return false;
              }
  
              @Override
              public void onTouchEvent(RecyclerView rv, MotionEvent event) {
  
              }
  
              @Override
              public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
  
              }
          });
  
  
      }
  
      private ArrayList&lt;DataObject&gt; getDataSet() {
          ArrayList results = new ArrayList&lt;DataObject&gt;();
          for (int index = 0; index &lt; 20; index++) {
              DataObject obj = new DataObject("Some Primary Text " + index,
                      "Secondary " + index);
              results.add(index, obj);
          }
          return results;
      }
  }
  </code></pre>
  
  <p>and <strong><em>MyRecyclerViewAdapter.java</em></strong></p>
  
  <pre><code>import android.support.v7.widget.RecyclerView;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  
  import java.util.ArrayList;
  
  public class MyRecyclerViewAdapter extends RecyclerView
          .Adapter&lt;MyRecyclerViewAdapter
          .DataObjectHolder&gt; {
      private static String LOG_TAG = "MyRecyclerViewAdapter";
      private ArrayList&lt;DataObject&gt; mDataset;
      private static MyClickListener myClickListener;
  
      public static class DataObjectHolder extends RecyclerView.ViewHolder
              implements View
              .OnClickListener {
          TextView label;
          TextView dateTime;
  
          public DataObjectHolder(View itemView) {
              super(itemView);
              label = (TextView) itemView.findViewById(R.id.textView);
              dateTime = (TextView) itemView.findViewById(R.id.textView2);
              Log.i(LOG_TAG, "Adding Listener");
              itemView.setOnClickListener(this);
          }
  
          @Override
          public void onClick(View v) {
              myClickListener.onItemClick(getAdapterPosition(), v);
          }
      }
  
      public void setOnItemClickListener(MyClickListener myClickListener) {
          this.myClickListener = myClickListener;
      }
  
      public MyRecyclerViewAdapter(ArrayList&lt;DataObject&gt; myDataset) {
          mDataset = myDataset;
      }
  
      @Override
      public DataObjectHolder onCreateViewHolder(ViewGroup parent,
                                                 int viewType) {
          View view = LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.card_view_row, parent, false);
  
          DataObjectHolder dataObjectHolder = new DataObjectHolder(view);
          return dataObjectHolder;
      }
  
      @Override
      public void onBindViewHolder(DataObjectHolder holder, int position) {
          holder.label.setText(mDataset.get(position).getmText1());
          holder.dateTime.setText(mDataset.get(position).getmText2());
      }
  
      public void addItem(DataObject dataObj, int index) {
          mDataset.add(index, dataObj);
          notifyItemInserted(index);
      }
  
      public void deleteItem(int index) {
          mDataset.remove(index);
          notifyItemRemoved(index);
      }
  
      @Override
      public int getItemCount() {
          return mDataset.size();
      }
  
      public interface MyClickListener {
          public void onItemClick(int position, View v);
      }
  }
  </code></pre>
  
  <p><strong><em>card_view_row.xml</em></strong> - </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:card_view="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"&gt;
  
      &lt;android.support.v7.widget.CardView
          android:id="@+id/card_view"
          android:layout_width="fill_parent"
          android:layout_height="100dp"
          android:layout_gravity="center"
          android:layout_margin="5dp"
          card_view:cardCornerRadius="2dp"
          card_view:contentPadding="10dp"&gt;
  
          &lt;RelativeLayout
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"&gt;
  
              &lt;TextView
                  android:id="@+id/textView"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignParentTop="true"
                  android:textStyle="bold"/&gt;
  
              &lt;TextView
                  android:id="@+id/textView2"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/textView"
                  android:layout_marginTop="10dp"/&gt;
          &lt;/RelativeLayout&gt;
      &lt;/android.support.v7.widget.CardView&gt;
  
  
  &lt;/LinearLayout&gt;
  </code></pre>