title: Android: Define onDraw Canvas Size
body: <p>I've removed my old code now as it wasn't working as I intended.  I was trying to use the onDraw canvas feature within a certain portion of the screen so that I could still have buttons and other text around my drawing.</p>
  
  <p><em><strong></em>***</strong><em>EDIT</em><strong><em>*</em>**</strong></p>
  
  <p>I've managed to fix this issue now.  A lot of what was suggested was helpful but I just couldn't get it to work with what I wanted.  That's probably more my fault than anything else so thanks to all those who offered advice.  Here's how I solved the issue.</p>
  
  <p>*1. First Define a View in the Layout File.</p>
  
  <pre><code>&lt;view
  class="com.project.MainActivity.Drawing"
  android:id="@+id/drawing_area"
  android:layout_width="700dp"
  android:layout_height="900dp"
  android:layout_centerInParent="true"/&gt;
  </code></pre>
  
  <p>*2. Then create a separate java class file with the following code:</p>
  
  <pre><code>public class Drawing extends View {
  Paint paint = new Paint();
  
  public Drawing(Context context) {
  super(context);
  }
  
  public Drawing(Context context, AttributeSet attrs) {
  super(context, attrs);
  }   
  
  @Override
  protected void onDraw(Canvas canvas) {  
  super.onDraw(canvas);
  
  //Draw Image Here//
  
  }
  </code></pre>
  
  <p>*3. Then call the Drawing from the main activity:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
  private Drawing mDrawingArea;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.percentage_count_layout);
    mDrawingArea = (Drawing)findViewById(R.id.drawing_area);  
  }
  </code></pre>