title: Adding a colored background with text/icon under swiped row when using Android's RecyclerView
body: <p><strong>EDIT: The real problem was that my <code>LinearLayout</code> was wrapped in another layout, which caused the incorrect behavior. The accepted answer by Sanvywell has a better, more complete example of how to draw a color under swiped view than the code snippet I provided in the question.</strong></p>
  
  <p>Now that <a href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ViewHolder.html" rel="noreferrer">RecyclerView</a> widget has native support for row swiping with the help of <a href="https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.html" rel="noreferrer">ItemTouchHelper</a> class, I'm attempting to use it in an app where rows will behave similarly to Google's Inbox app. That is, swiping to the left side performs one action and swiping to the right does another. </p>
  
  <p>Implementing the actions themselves was easy using <a href="https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.SimpleCallback.html" rel="noreferrer">ItemTouchHelper.SimpleCallback</a>'s <code>onSwiped</code> method. However, I was unable to find a simple way to set color and icon that should appear under the view that's currently being swiped (like in Google's Inbox app).</p>
  
  <p>To do that, I'm trying to override <a href="https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.SimpleCallback.html" rel="noreferrer">ItemTouchHelper.SimpleCallback</a>'s <code>onChildDraw</code> method like this:</p>
  
  <pre><code>@Override
  public void onChildDraw(Canvas c, RecyclerView recyclerView,
                          RecyclerView.ViewHolder viewHolder, float dX, float dY,
                          int actionState, boolean isCurrentlyActive) {
      RecyclerViewAdapter.ViewHolder vh = (RecyclerViewAdapter.ViewHolder) viewHolder;
      LinearLayout ll = vh.linearLayout;
  
      Paint p = new Paint();
      if(dX &gt; 0) {
          p.setARGB(255, 255, 0, 0);
      } else {
          p.setARGB(255, 0, 255, 0);
      }
  
      c.drawRect(ll.getLeft(), ll.getTop(), ll.getRight(), ll.getBottom(), p);
  
      super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
  }
  </code></pre>
  
  <p>Determining the swipe direction from dX and setting the appropriate color works as intended, but the coordinates I get from the <code>ViewHolder</code> always correspond to the place where the first <code>LinearLayout</code> was inflated.</p>
  
  <p>How do I get the correct coordinates for the <code>LinearLayout</code> that's in the currently swiped row? Is there an easier way (that doesn't require to override <code>onChildDraw</code>) to set the background color and icon?</p>