问题
I create custom view based on LinearLayout. Class extends the LinearLayout class, in layout I have:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<merge>
some staff here
</merge>
</layout>
Android Studio shows the the warning Element merge is not allowed here
, but app works.
What's wrong?
回答1:
I believe it's just a glitch in Android studio. Even the official documentation has merge
as a direct child of layout
: https://developer.android.com/topic/libraries/data-binding/index.html
Edit: I filed a bug there: https://code.google.com/p/android/issues/detail?id=286406&thanks=286406&ts=1490873944
Edit2: Bug is fixed \o/ in AS 3.5 Canary 12
回答2:
Actually you dont need merge at all here since you have layout in root for databisnig. <merge> tag here is redundant!
Use the <merge> Tag
The tag helps eliminate redundant view groups in your view hierarchy when including one layout within another
From : Android documentation
Layout as merge wont be drawn and system ignores them during drawing.
To approve that I did tracking layouts by Hierarchy View in Android Device Monitor for layout .. it doesn't exist which means its doing the same job as merge tag . you can check it by yourself!
Hope that may help..
回答3:
Make <merge>
be the first tag in the file.
来源:https://stackoverflow.com/questions/32426646/android-studio-shows-warning-element-merge-is-not-allowed-here