title: Oval shape clipped when created programmatically
body: <p>I've got a clipping problem.</p>
  
  <p>First, I tried to display an oval shape with Xml only. I had the following code:</p>
  
  <p><em>res/drawable/circle.xml</em></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;shape
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:shape="oval" &gt;
      &lt;size
          android:width="240dp"
          android:height="240dp" /&gt;
      &lt;solid
          android:color="#FFFFFF" /&gt;
      &lt;stroke
          android:width="2dp"
          android:color="#EEEEEE" /&gt;
  &lt;/shape&gt;    
  </code></pre>
  
  <p>*res/layout/test.xml</p>
  
  <pre><code>....
  &lt;RelativeLayout
      android:id="@+id/circle_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1" &gt;
  
      &lt;ImageView
          android:src="@drawable/circle"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_centerInParent="true" /&gt;
  
  &lt;/RelativeLayout&gt;
  ....
  </code></pre>
  
  <p>It works perfectly, and gave me this: <a href="http://imageshack.us/photo/my-images/546/fj04.jpg/" rel="noreferrer">Screenshot</a></p>
  
  <p>The problem is, for various reason, I must do the same progammatically.</p>
  
  <p>I've got this code:</p>
  
  <pre><code>RelativeLayout layout = (RelativeLayout) findViewById(R.id.circle_layout);
  
  ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
  drawable.getPaint().setColor(Color.parseColor("#EEEEEE"));
  drawable.getPaint().setStyle(Style.STROKE);
  drawable.getPaint().setStrokeWidth(dpToPx(2));
  drawable.getPaint().setAntiAlias(true);
  drawable.setIntrinsicHeight(dpToPx(240));
  drawable.setIntrinsicWidth(dpToPx(240));
  
  ImageView iv = new ImageView(this);
  iv.setImageDrawable(drawable);
  
  RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
  RelativeLayout.LayoutParams.WRAP_CONTENT,
  RelativeLayout.LayoutParams.WRAP_CONTENT);
  lp.addRule(RelativeLayout.CENTER_IN_PARENT);
  iv.setLayoutParams(lp);
  
  layout.addView(iv);
  </code></pre>
  
  <p>dpToPx function is:</p>
  
  <pre><code>private float scale = 0;
  
  private float getScale() {
      if (scale == 0)
          scale  = this.getResources().getDisplayMetrics().densityDpi / 160f;
      return scale;
  }
  
  public float dpToPx(float dp) {
      return dp * getScale();
  }
  </code></pre>
  
  <p>... this should gave me the same thing right? Well it gave a slightly larger circle, with top, right, bottom and left edges clipped. Here's a screenshot (same region of the screen than the previous one): <a href="http://imageshack.us/photo/my-images/29/hx91.jpg/" rel="noreferrer">Screehshot</a></p>
  
  <p>Someone has an idea on what and why?</p>
  
  <p>Thank you.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>if I set the stoke width to a higher value (12dp), I've got this: <a href="http://imageshack.us/photo/my-images/607/bgvu.jpg/" rel="noreferrer">Screenshot</a></p>