XML attributes from merge layout to RelativeLayout via inflate
I think the problem is that merge happens to the children of the merge tag, and not the merge itself.
AFAIK, you are correct. <merge>
is a placeholder, not a ViewGroup
.
I know I can add everything to a LayoutParams, and then add my MyRelativeLayoutSubclass with that LayoutParams, but I would like escape that, that's a lot of unnecessary code.
Create an XML layout file containing a MyRelativeLayoutSubclass
element, and put your attributes there. Then, inflate that layout.
Extracting all the attributes into Style was a solution for me. As a bonus it's screen-size dependent unlike the hard-coded attributes or Java-code. Maybe you can go further and put it into the Theme attributes.
<com.example.widget.MyCustomView
android:id="@+id/my_custom_view"
style="@style/MyCustomView.Default"/>