android - How many ViewStubs is too many for a single layout XML file? -
i have layout defined in xml file(base_layout.xml
) may contain 20+ viewstub
definitions in addition 3-5 other views such imageview
, linearlayout
containing 3-5 imagebutton
views.
should concerned how many viewstub
views place in layout file?
i read on developer.android site:
a viewstub dumb , lightweight view. has no dimension, not draw , not participate in layout in way. means viewstub cheap inflate , cheap keep in view hierarchy
is cheap enough have 20+ of them? not being inflated of course, 1-2 @ time.
when cheap enough
or talk of being concerned
, regarding performance of ui
edit: trying accomplish: create layout xml file can skeleton of activities. in each activity
, inflate correct viewstub
activity's layout. since have many activities requiring same skeleton, wish re-use as possible
i have activity
class parent of of activities. parent class calls setcontentview(r.layout.base_layout);
. each child activity, doing inflating corresponding viewstub
inside base_layout.xml
. doing allows me have customized ui same skeleton view used on of activity layouts
i don't think you'll see big performance hit. it's still cheaper having of them inflated begining.
the downside of having many stubs lose sight of whole design. maybe makes more sense group several views/items 1 viewgroup. maybe explain you're attempting , see if there better way realize it
edit: well, instead of having multiple viewstubs include different subviews
<viewstub android:id="@+id/stub" android:inflatedid="@+id/activity1" android:layout="@layout/myactivity1" /> <viewstub android:id="@+id/stub2" android:inflatedid="@+id/activity2" android:layout="@layout/myactivity2" />
just have single viewstub , in acitivities oncreate() like
setcontentview(r.layout.base_layout); viewstub stub = (viewstub)findviewbyid(r.id.stub); stub.setinflateid(r.id.activity1); stub.setlayoutresource(r.layout.myactivity2); stub.inflate();
this way you'd still have 1 viewstub in base_layout, setup in code before inflating.
Comments
Post a Comment