Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Curious, this behavior does not seem to be universally true. I can run a simple example in the emulator or on one of my Nexus devices and the application has no problem inflating a main layout with the <code>&lt;merge&gt;</code> tag as the root of the hierarchy. Can you reproduce this on multiple devices?</p> <p>Technically, just from a glance at the AOSP, this behavior is not possible with the Android <code>Window</code> and <code>Activity</code> implementation unless a particular OEM has modified its behavior (Motorola is notorious for doing this). In the AOSP source:</p> <ol> <li>The exception can only come about when <code>LayoutInflater.inflate()</code> is called with a <code>null</code> parent view parameter.</li> <li><code>Activity</code> just passes <code>setContentView()</code> off to its parent <code>Window</code></li> <li><code>Window</code> calls <code>LayoutInflater.inflate()</code> with the content view as the parent, and if it were null at this stage a nasty <code>RuntimeException</code> would have been thrown by the framework code.</li> </ol> <p>As a side note, this may not be something you want to do anyway. I understand the reason for wanting to replace a seemingly useless parent in your hierarchy, but one thing that guarantees is that your application always knows what its parent is so it can properly expect <code>LayoutParams</code> to be evaluated. When using <code>&lt;merge&gt;</code>, the root content view of your hierarchy could be a <code>FrameLayout</code>, <code>LinearLayout</code>, or other depending on the version of Android on the device, and this may cause confusing behavior if you expect root <code>LayoutParams</code> to behave in a specific way.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload