title: Custom Android control with children
body: <p>I'm trying to create a <strong>custom Android control</strong> that <strong>contains a LinearLayout</strong>. You can think of it as an extended LinearLayout with fancy borders, a background, an image on the left...</p>
  
  <p>I could do it all in XML (works great) but since I have dozens of occurences in my app it's getting hard to maintain. I thought it would be nicer to have something like this:</p>
  
  <pre><code>/* Main.xml */
  &lt;MyFancyLayout&gt;
      &lt;TextView /&gt;   /* what goes inside my control's linear layout */
  &lt;/MyfancyLayout&gt;
  </code></pre>
  
  <p>How would you approach this? I'd like to avoid re-writing the whole linear layout onMeasure / onLayout methods. This is what I have for the moment:</p>
  
  <pre><code>/* MyFancyLayout.xml */
  &lt;TableLayout&gt;
      &lt;ImageView /&gt;
      &lt;LinearLayout id="container" /&gt;   /* where I want the real content to go */
  &lt;/TableLayout&gt;    
  </code></pre>
  
  <p>and </p>
  
  <pre><code>/* MyFancyLayout.java */
  public class MyFancyLayout extends LinearLayout
  {
      public MyFancyLayout(Context context) {
          super(context);
          View.inflate(context, R.layout.my_fancy_layout, this);
      }
  }
  </code></pre>
  
  <p>How would you go about inserting the user-specified content (the TextView in main.xml) in the right place (id=container)?</p>
  
  <p>Cheers!</p>
  
  <p>Romain</p>
  
  <p>----- edit -------</p>
  
  <p>Still no luck on this, so I changed my design to use a simpler layout and decided to live with a bit of repeated XML. Still very interested in anyone knows how to do this though!</p>