Custom Android layout that handles its children
- by Gromix
Hi,
I'm trying to create a custom Android control to emulate a LinearLayout with a fancier display. Basically, I want the exact behaviour of a LinearLayout, but also borders, a background, ...
I could do it all in XML (works great) but since I have dozens of occurences in my app it's getting hard to maintain. I thought it would be nicer to have something like this:
/* Main.xml */
<MyFancyLayout>
<TextView />
<ImageView />
</MyfancyLayout>
My problem is, I don't want to have to re-write LinearLayout, so is there a way to only change its appearance? I got as far as this, which doesn't work... can anyone think of a better approach?
/* MyFancyLayout.xml */
<merge>
... the complex hierarchy to make it look like what I want
... with background attributes etc
</merge>
and
/* MyFancyLayout.java */
public class MyFancyLayout extends LinearLayout
{
// inflate the XML
// move all the real children (as given by main.xml) to the inflated layout
// do I still need to override onMeasure and onLayout?
}
Cheers!
Romain