Thursday 15 January 2015

android - The most lightweight way to dynamically load different views at runtime? -



android - The most lightweight way to dynamically load different views at runtime? -

sometimes may need load different views 1 page, created container element @ layout xml file, e.g.,

<framelayout android:id="@+id/container android:layout_width="match_parent" android:layout_height="wrap_content/>

the above framelayout linearlayout, relativelayout or whatever. @ runtime, utilize container root of dynamically added view. worked fine container layout incremented 1 level of view hierarchy.

there merge element in xml, can't programmatically merge layouts.

there viewstub, still can't programmatically load different layouts or views

i'm curious if there more lightweight way?

you can utilize <merge> correctly, have create sure inflate calls has parent specified, , inflated layout must added parent (pass true 3rd param):

linearlayout somecontainer = ... getlayoutinflater().inflate(r.layout.your_merge_layout, somecontainer, true);

then not additional depth, children of <merge> added somecontainer directly.

android android-layout

No comments:

Post a Comment