title: Android view doesn't draw when applied a layout_below parameter
body: <p>I have this view i'm trying to implement, which is basically a thumb that is movable around a horizontal track.</p>
  
  <p>It draws fine when it is in a RelativeLayout without any special layout parameters such as layout_below, but once i put a layout_below parameter on it, it doesn't draw at all!</p>
  
  <p>What might be the cause of this?</p>
  
  <p>public class TrackSlider extends View {</p>
  
  <pre><code>/**
   * The thumb of the slider will be limited to move so that it's center does
   * not go beyond the width of the track.
   */
  public static final int THUMB_ANCHOR_CENTER = 0;
  
  /**
   * The thumb of the slider will be limited to move so that it's edges do not
   * go beyond the width of the track.
   */
  public static final int THUMB_ANCHOR_EDGES = 1;
  
  private float mSliderPosition;
  private float mSnapPosition = 0f;
  private boolean mSnapEnabled = false;
  private int mThumbAnchor;
  
  private Drawable mThumbDrawable;
  private Drawable mTrackDrawable;
  private int mTrackWidth;
  private int mSlideRange;
  private int mThumbWidth;
  private int mThumbXOffset;
  
  public TrackSlider(Context context, AttributeSet attrs) {
      super(context, attrs);
      TypedArray a = getContext().obtainStyledAttributes(attrs,
              styleable.TrackSlider);
      final int N = a.getIndexCount();
      for (int i = 0; i &lt; N; i++) {
          int attr = a.getIndex(i);
          switch (attr) {
          case styleable.TrackSlider_snapEnabled:
              setSnapEnabled(a.getBoolean(i, false));
              break;
          case styleable.TrackSlider_snapPosition:
              setSnapPosition(a.getFloat(i, 0.0f));
              break;
          case styleable.TrackSlider_startPosition:
              setThumbPosition(a.getFloat(i, 0.0f));
              break;
          case styleable.TrackSlider_thumb:
              setThumbDrawable(a.getDrawable(i));
              break;
          case styleable.TrackSlider_track:
              setTrackDrawable(a.getDrawable(i));
              break;
          case styleable.TrackSlider_thumbAnchor:
              mThumbAnchor = 0;//a.getInt(i, THUMB_ANCHOR_CENTER);
              break;
          }
      }
  }
  
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
      int measuredWidth = 0, measuredHeight = 0;
      switch (MeasureSpec.getMode(widthMeasureSpec)) {
      case MeasureSpec.EXACTLY:
          measuredWidth = MeasureSpec.getSize(widthMeasureSpec);
          break;
      case MeasureSpec.AT_MOST:
          measuredWidth = Math.min(
                  MeasureSpec.getSize(widthMeasureSpec),
                  Math.max(mTrackDrawable.getIntrinsicWidth(),
                          mThumbDrawable.getIntrinsicWidth()));
          break;
      case MeasureSpec.UNSPECIFIED:
          measuredWidth = Math.max(mTrackDrawable.getIntrinsicWidth(),
                  mThumbDrawable.getIntrinsicWidth());
          break;
      }
      switch (MeasureSpec.getMode(heightMeasureSpec)) {
      case MeasureSpec.AT_MOST:
          measuredHeight = Math.min(MeasureSpec.getSize(heightMeasureSpec),
                  Math.max(mTrackDrawable.getIntrinsicHeight(),
                          mThumbDrawable.getIntrinsicHeight()));
          break;
      case MeasureSpec.EXACTLY:
          measuredHeight = MeasureSpec.getSize(heightMeasureSpec);
          break;
      case MeasureSpec.UNSPECIFIED:
          measuredHeight = Math.max(mTrackDrawable.getIntrinsicHeight(),
                  mThumbDrawable.getIntrinsicHeight());
          break;
      }
      setMeasuredDimension(measuredWidth, measuredHeight);
  }
  
  @Override
  protected void onLayout(boolean changed, int left, int top, int right,
          int bottom) {
      super.onLayout(changed, left, top, right, bottom);
      int w = right - left;
      if (mThumbAnchor == THUMB_ANCHOR_CENTER) {
          mTrackWidth = w - getPaddingRight() - getPaddingLeft()
                  - mThumbWidth;
      } else {
          mTrackWidth = w - getPaddingRight() - getPaddingLeft();
      }
      mThumbXOffset = getPaddingLeft();
      mSlideRange = w - getPaddingRight() - getPaddingLeft()
              - mThumbWidth;
      mTrackDrawable.setBounds((w - mTrackWidth) / 2, top + getPaddingTop(), (w + mTrackWidth) / 2, getBottom() - getPaddingBottom());
      mThumbDrawable.setBounds(mThumbXOffset,
              getPaddingTop() + getTop(), mThumbXOffset + mThumbWidth,
              getBottom() - getPaddingBottom());
  }
  
  @Override
  protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);
      int pos = (int) (mSliderPosition * mSlideRange);
      Rect r = new Rect();
      mThumbDrawable.copyBounds(r);
      r.offset(pos, 0);
      mThumbDrawable.setBounds(r);
      mTrackDrawable.draw(canvas);
      mThumbDrawable.draw(canvas);
      r.offset(-pos, 0);
      mThumbDrawable.setBounds(r);
  }
  
      /* getters and setters... */
  </code></pre>
  
  <p>}</p>
  
  <p>layout file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:twoday="http://schemas.android.com/apk/res/com...."
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:paddingLeft="10dp"
      android:paddingRight="10dp" &gt;
  
      &lt;TextView
          android:id="@+id/message"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textStyle="normal" /&gt;
  
      &lt;Button
          android:id="@+id/btnContinue"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentRight="true"
          android:layout_below="@id/message"
          android:layout_marginRight="10dp"
          android:background="@drawable/btn_dialog_continue" /&gt;
  
      &lt;Button
          android:id="@+id/btnCancel"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignTop="@+id/btnContinue"
          android:layout_toLeftOf="@id/btnContinue"
          android:background="@drawable/btn_dialog_cancel" /&gt;
  
      &lt;com.twoday.gallerys.views.TrackSlider
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/btnCancel"
          twoday:snapEnabled="true"
          twoday:startPosition="0.5"
          twoday:thumb="@drawable/confirm_slider_thumb"
          twoday:thumbAnchor="center"
          twoday:track="@drawable/confirm_slider_track" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>