title: Android: drawing a canvas to a view
body: <p>I am trying to draw a canvas that contains a circle to a view that was defined previously via findViewById() like this</p>
  
  <pre><code>    View v = findViewById(R.id.view1);
      Bitmap b = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
      Canvas c = new Canvas(b);
      Paint paint = new Paint();
      paint.setStyle(Paint.Style.FILL);
      paint.setColor(Color.WHITE);
      c.drawCircle(v.getMeasuredWidth() / 2, v.getMeasuredHeight() / 2, v.getMeasuredWidth() / 4, paint);
      v.draw(c);
  </code></pre>
  
  <p>but there is no circle drawn to the view</p>
  
  <p>My whole activity:</p>
  
  <pre><code>package com.burrlieexample.test;
  
  import android.app.Activity;
  import android.graphics.Bitmap;
  import android.graphics.Canvas;
  import android.graphics.Color;
  import android.graphics.Paint;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  
  public class InstructionsActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          Log.d("DEBUG", "InstruciotnActivity");
          setContentView(R.layout.activity_instructions);
  
          Button okay = (Button) findViewById(R.id.okButton);
          okay.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  finish();
              }
          });
  
      }
  
      @Override
      public void onWindowFocusChanged(boolean hasFocus) {
          // TODO Auto-generated method stub
          super.onWindowFocusChanged(hasFocus);
          Log.d("DEBUG", "onFocusChanged");
  //im doing this stuff in onWindowfocusChanged because getWidth returns 0 in onCreate
          View v = findViewById(R.id.view1);
          Log.d("DEBUG", "" + v.getMeasuredWidth() + ", " + v.getMeasuredHeight());
          Bitmap b = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
          Canvas c = new Canvas(b);
          Paint paint = new Paint();
          paint.setStyle(Paint.Style.FILL);
          paint.setColor(Color.WHITE);
          c.drawCircle(v.getMeasuredWidth() / 2, v.getMeasuredHeight() / 2, v.getMeasuredWidth() / 4, paint);
          v.draw(c);
  
      }
  
  
      @Override
      protected void onDestroy() {
          super.onDestroy();
      }
  }
  </code></pre>
  
  <p>and the View is in my layout xml file like this</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="#D0F3FF"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context="com.burrlieexample.test.InstructionsActivity" &gt;
  
      &lt;Button
          android:id="@+id/okButton"
          style="?android:attr/buttonStyleSmall"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_centerHorizontal="true"
          android:layout_marginBottom="52dp"
          android:background="#00455F"
          android:hapticFeedbackEnabled="true"
          android:text="Ok!" /&gt;
  
      &lt;View
          android:id="@+id/view1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_above="@+id/okButton"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>So when the Activity starts the only things i see are the button and the background of my relative layout</p>