title: Setting CardView elevation programmatically
body: <p>I do not know if this approach is the best, but I have the following problem:</p>
  
  <p>I want a list item (a CardView) in a RecyclerView to be animated when it's button was clicked, so that this button, some other views inside this item and the background of the CardView changes.</p>
  
  <p>I am catching the animateChange from a custom RecyclerView.ItemAnimator:
  (until now the animation is just a fade defined in the xml via animateLayoutChanges)</p>
  
  <pre><code>public boolean animateChange(@NonNull RecyclerView.ViewHolder oldHolder, @NonNull RecyclerView.ViewHolder newHolder, @NonNull ItemHolderInfo preLayoutInfo, @NonNull ItemHolderInfo postLayoutInfo) {
      Log.d("Animation", "Test");
      final MyAdapter.MyViewHolder viewHolder = (MyAdapter.MyViewHolder) newHolder;
  
      viewHolder.mButtons.setVisibility(View.GONE);
      viewHolder.mHints.setVisibility(View.GONE);
      viewHolder.mImageView.setVisibility(View.GONE);
  
      ViewGroup.LayoutParams layoutParams = viewHolder.containerCardView.getLayoutParams();
      layoutParams.height = 192;
      viewHolder.containerCardView.setLayoutParams(layoutParams);
      viewHolder.containerCardView.setBackgroundResource(R.drawable.some_background);
      viewHolder.containerCardView.setElevation(20f);
  
      return true;
  }
  </code></pre>
  
  <p>As you can see, I am setting the background manually in the animateChange. Everything works fine (or lets say at least as expected) except for the elevation of the CardView. I tried to set the elevation by hand, but there is no elevation shown.</p>
  
  <p>EDIT______</p>
  
  <p>My CardView has an ImageView and a button inside it. When pressing the button, the button itself and the picture should fade out and there shall be a red line on the right side of the cardView. I tried to achieve that by setting the background (with setBackgroundResource) to this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  &lt;item&gt;
      &lt;shape xmlns:android="http://schemas.android.com/apk/res/android"
             android:shape="rectangle"&gt;
          &lt;gradient
              android:angle="180"
              android:centerColor="@android:color/transparent"
              android:centerX="0.1"
              android:startColor="@android:color/holo_red_dark"/&gt;
          &lt;corners
              android:bottomLeftRadius="2dip"
              android:bottomRightRadius="2dip"
              android:topLeftRadius="2dip"
              android:topRightRadius="2dip"/&gt;
      &lt;/shape&gt;
  &lt;/item&gt;
  
  &lt;item android:right="4dp"&gt;
      &lt;shape android:shape="rectangle"&gt;
          &lt;solid android:color="@android:color/white" /&gt;
      &lt;/shape&gt;
  &lt;/item&gt;
  &lt;/layer-list&gt;
  </code></pre>
  
  <p>Which is just an xml drawable with a red line on the right. Do you have any suggestions for another way to approach my goal?</p>