title: How to create a simple custom View?
body: <p>I would like to create an custom <code>View</code> on Android. I have tried to do it as simple as possible and created an almost empty class <code>MyView</code> and used it in my <code>LinearLayout</code> but the application fails on start with "Force Close". How can I do a simple custom <code>View</code>? According to <a href="http://developer.android.com/guide/topics/ui/custom-components.html" rel="nofollow noreferrer">Building Custom Components</a> the <code>View</code> gets the size 100x100 if I don't override <code>onMeasure()</code>.</p>
  
  <pre><code>public class MyView extends View {
  
      public MyView(Context context) {
          super(context);
      }
  }
  </code></pre>
  
  <p>And I use it in a <code>LinearLayout</code> with:</p>
  
  <pre><code>&lt;view
      class="com.example.MyView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_weight="0.0" /&gt;
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <hr>
  
  <p>If I use the constructor that <a href="https://stackoverflow.com/questions/4439456/how-to-create-a-simple-custom-view/4440209#4440209">itemon</a> suggest and the corresponding call to the superclass. Then the "Force Close" is gone, but my <code>LinearLayout</code> is broken, the components after <code>MyView</code> isn't shown.</p>
  
  <p>Here is my <code>main.xml</code>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical"
      &gt;
  &lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_weight="0.0"
      android:background="#f00"
      android:text="Hello"
  /&gt;
  &lt;view
      class="com.example.MyView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_weight="0.0"
  /&gt;
  &lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_weight="0.0"
      android:background="#00f"
      android:text="World"
  /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>