android - Compound layout -



android - Compound layout -

i want create custom layout cut down redundancy in code. every layoutfile has 30 lines of code identical.

my goal create custom layout/view can hold in children.

<baselayout xmlns:...> <!-- normal content --> <button /> <label /> </baselayout>

while above xml holds of content, baselayout in xml containing other views , functionality:

<framelayout xmlns:...> <linearlayout><!-- contains header--></linearlayout> <linearlayout><!-- individual content here--></linearlayout> <framelayout><!-- contains loading screen overlay --></framelayout> </framelayout>

so children above xml should inserted sec linear-layout. have succeeded doing so. confronted layout problems (match parents not match parents , wraps)

my approach extending linearlayout next logic:

/** * extracting children , adding them inflated base-layout */ @override protected void onfinishinflate() { super.onfinishinflate(); view view = layoutinflater.from(getcontext()).inflate(r.layout.base_layout, null); linearlayout linearlayout = (linearlayout) view.findviewbyid(r.id.base_layout_children); while(0 < getchildcount()) { view kid = getchildat(0); linearlayout.marginlayoutparams layoutparams = (marginlayoutparams) child.getlayoutparams(); removeviewat(0); linearlayout.addview(child, layoutparams); } this.addview(view); }

is there better, cleaner approach capsule xml , reuse basis layout? how prepare match_parent issue?

while writing post , thinking hard how explain best, solution match_parent issue became clear. though question remains if there improve approach whole problem.

//solution: this.addview(view, new viewgroup.layoutparams(viewgroup.layoutparams.match_parent, viewgroup.layoutparams.match_parent)); //wrong: this.addview(view);

android android-layout

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -