title: Android - Add a custom view to a component in a xml layout
body: <p>I have an abstract class extended from the class View, and 4 subclasses to perform a series of vectorial drawings. Then I have a layout with four Buttons and a View to show the drawings. Depending on which button is clicked, different figures should be drawn in that View. The problem is that when I click one button, the figures are drawn filling the entire screen, the buttons disappear. How could this problem be solved?</p>
  
  <pre><code>public abstract class DrawFiguresWithDimensions extends View{
      public DrawingFiguresWithDimensions(Context context)
      //...
  }
  public class DrawRectangleWithDimensions extends DrawFiguresWithDimensions {..}
  public class DrawTWithDimensions extends DrawFiguresWithDimensions {..}
  public class DrawDobleTWithDimensions extends DrawFiguresWithDimensions {..}
  public class DrawBoxWithDimensions extends DrawFiguresWithDimensions {..}
  </code></pre>
  
  <p>Here is the "activity_main.xml":</p>
  
  <pre><code>&lt;LinearLayout
  android:id="@+id/mainLayout"
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  xmlns:custom="http://schemas.android.com/apk/res-auto"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:layout_weight="10"
  tools:context=".MainActivity"&gt;
  &lt;LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      android:layout_weight="1"
      android:weightSum="4"
      &gt;
      &lt;Button
          android:id="@+id/btnSecRec"
          android:text="Rec"
          android:onClick="btnSecRec"
          android:layout_weight="1"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" /&gt;
      &lt;Button
          android:id="@+id/btnSecT"
          android:text="T"
          android:onClick="btnSecT"
          android:layout_weight="1"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" /&gt;
      &lt;Button
          android:id="@+id/btnSecDobleT"
          android:text="DT"
          android:onClick="btnSecDobleT"
          android:layout_weight="1"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" /&gt;
      &lt;Button
          android:id="@+id/btnSecCajon"
          android:text="Box"
          android:onClick="btnSecCajon"
          android:layout_weight="1"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" /&gt;
      &lt;/LinearLayout&gt;
  &lt;View class="com.tari.drawfigureswithdimensions.DrawFiguresWithDimensions"
      android:id="@+id/viewDatosSec"
      android:layout_weight="8"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      /&gt;
  </code></pre>
  
  <p></p>
  
  <p>"MainActivity.java"</p>
  
  <pre><code>public class MainActivity extends Activity {
  
  DrawRectangleWithDimensions sec1;
  DrawTWithDimensions sec2;
  DrawDoubleTWithDimensions sec3;
  DrawBoxWithDimensions sec4;
  
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  }
  
  public void btnSecRec(View view){
      sec1 = new DrawRectangleWithDimensions(this);
      sec1.setFigure(10, 40);
      setContentView(sec1);
  }
  public void btnSecT(View view){
      sec2 = new DrawTWithDimensions(this);
      sec2.setFigure(100, 20, 20, 70);
      setContentView(sec2);
  }
  public void btnSecDobleT(View view){
      sec3 = new DrawDoubleTWithDimensions(this);
      sec3.setFigure(100, 20, 20, 90, 50, 25);
      setContentView(sec3);
  }
  public void btnSecCajon(View view){
      sec4 = new DrawBoxWithDimensions(this);
      sec4.setFigure(100, 20, 20, 80);
      setContentView(sec4);
  }
  </code></pre>