title: How can I preview a custom android component layout?
body: <p>I've created a custom view which extends <code>RelativeLayout</code>, and I want to preview how it looks in the designer.</p>
  
  <p>The java is something like this:</p>
  
  <pre><code>// The view for a snap in the search/browse fragment.
  public class MyView extends RelativeLayout
  {
      public MyView(Context context, AttributeSet attrs, int defStyle)
      {
          super(context, attrs, defStyle);
          LayoutInflater inflater = LayoutInflater.from(context);
          inflater.inflate(R.layout.the_layout, this);
      }
  
      public void setData(String text)
      {
          mText.setText(text);
      }
  
      // *** Views ***
      private TextView mText;
  
      @Override
      protected void onFinishInflate()
      {
          super.onFinishInflate();
  
          mText = (TextView)findViewById(R.id.text);
      }
  }
  </code></pre>
  
  <p>And the XML is like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;TextView
          android:id="@+id/text"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
  
      &lt;!-- (And lots more views) --&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>There are a few problems with this however:</p>
  
  <ol>
  <li>This actually creates a <code>RelativeLayout</code> within a <code>RelativeLayout</code> which is pointless. It can be solved by changing the XML <code>&lt;RelativeLayout&gt;</code> to a <code>&lt;merge&gt;</code> but then I can't preview the layout at all!</li>
  <li>I want to use the <code>isInEditor()</code> function (or whatever it is called) in the java to add some sample data for previewing purposes, but I can't find a way to tell the XML editor that it should display a preview of my class instead of the actual XML.</li>
  </ol>
  
  <p>One unsatisfying solution I can think of is to create an empty <code>preview.xml</code> file with only <code>&lt;com.foo.bar.MyView/&gt;</code> in it... But that seems kind of silly. Is there a better way? (I don't really care about editing as much as previewing, since - let's face it - Eclipse/ADT are way too slow and flaky to make graphical layout editing usable.)</p>