title: Using a non-android namespace prefix in child elements in a layout
body: <p>I am trying to use custom attributes in some Android layouts, but I am getting an error (from Eclipse) when I try to use a namespace prefix other than <code>android:</code> in a child element.  Note that it works ok when I use the <code>custom:</code> namespace prefix in the root/parent element in the file, just not the child element.  </p>
  
  <p>For example, here's a simple layout with the custom namespace specified:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:custom="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      custom:my_tag1="whatever"&gt;                            &lt;!-- compiles fine --&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:scaleType="fitCenter"
          custom:my_tag2="true"/&gt;                           &lt;!-- generates an error --&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>The error that Eclipse gives (only on the <em>second</em> attempt to use the <code>custom:</code> prefix) is:</p>
  
  <blockquote>
    <p>Unexpected namespace prefix "custom" found for tag ImageView.</p>
  </blockquote>
  
  <p>If I make my root element an <code>ImageView</code> instead of a <code>LinearLayout</code>, the prefix is accepted.  So it seems to be just a problem using the namespace prefix in a child element.</p>
  
  <p>Also, if I try to add another <code>xmlns:custom="http://schemas.android.com/apk/res-auto"</code> attribute to the ImageView, it complains as well.</p>
  
  <p>If it helps, here is the <code>attrs.xml</code> file I'm using with the above:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
      &lt;attr name="my_tag1" format="string"/&gt;
      &lt;attr name="my_tag2" format="boolean"/&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>I've seen some stuff online that leads me to believe what I want to do should be possible.  For example, in the accepted answer <a href="https://stackoverflow.com/questions/3441396/defining-custom-attrs">here</a>, Qberticus uses the prefix "whatever" in a child class.  Similarly in the post <a href="http://blog.pocketjourney.com/2008/05/02/android-tutorial-42-passing-custom-variables-via-xml-resource-files/" rel="nofollow noreferrer">here</a>.</p>
  
  <p>I don't get it.  Is using a non-android namespace prefix just not allowed for child elements, or am I doing something wrong?</p>