performance - Most Performant Android ViewGroup to Use For Independantly Positioned Children? - RelativeLayout vs FrameLayout -


i'm no android expert aware of discussions regarding appropriate use of linearlayout , relativelayout, keeping view hierarchy small possible, avoid unnecessary passes of onmeasure(), etc.

lets imagine have 2 imageview's want position independently, first in center of parent , second in bottom left of parent. (note vastly simplified example of far more complex real life requirements).

the obvious way solve using relativelayout...

<relativelayout      android:layout_width="match_parent"     android:layout_height="match_parent" >      <imageview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centerinparent="true"         android:src="@drawable/first_image" />      <imageview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignright="true"         android:layout_alignbottom="true"         android:src="@drawable/second_image" />  </relativelayout> 

however keeps telling me relativelayout isn't appropriate in situation because don't want organise children relative each other. want position children according parent , wonder if using relativelayout causes unnecessary layout calculations don't require.

i wondering if there viewgroup type perform better? totally possible achieve want framelayout example i've no idea if more performant or if abusing intent of framelayout etc...

<framelayout      android:layout_width="match_parent"     android:layout_height="match_parent" >      <imageview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="center"         android:src="@drawable/first_image" />      <imageview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="right|bottom"         android:src="@drawable/second_image" />  </framelayout> 

maybe there layout type unaware of?

short answer

given information have provided, framelayout has chance of performing better. may have learned watching (adam powell quote in google i/o 2013 conference),

[...] relativelayouts measure child views more once in order solve of constraints give it. so, being generic has cost [...]

from read , understood, not guaranteed , depends on constraints give it.

long answer

it depends.

we read romain guy blog post : android layout tricks #1, said people misinterpret post , started using relativelayout everywhere.

this post, if haven't read it, talks how removing 1 hierarchy level using relativelayout instead of linearlayout saves loading time in list.

basically, means if don't need them, described

[...] have 2 imageviews want position independently [...] don't want organize children relative each other

you should not use them because of reason.

concrete example of : "don't use them if don't need to."

for instance, in 1 of our applications, have serious performance issues on devices running gingerbread -- want support.

our complex layout involves vertical scrollview, attached current activity, in have several containers , 1 horizontalscrollview displays images , information contained in complex linearlayout.

we started replace linearlayout relativelayout. result: no obvious improvement -- equivalent or maybe worse.

since layout complex, adding more relativelayouts embedded in each other increased onmeasure() calls made single draw.

even small circular progressbar spamming ui thread several measure calls because in 1 of embedded relativelayout triggered recalculations of whole view.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -