Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PercentRelativeLayout is more Performant?

I always use LinearLayout and RelativeLayouts, and i was reading about the "new" PercentRelativeLayout. I have a few questions:

  • Should i always start using this one or only in cases of nested weights with linearlayout?

  • Is this more performant than the others?

Any other information about PercentRelativeLayout it will be welcome.

Thanks!

like image 630
JpCrow Avatar asked Jan 20 '16 19:01

JpCrow


People also ask

What is percentrelativelayout in Android?

PercentRelativeLayout class extends from Relative Layout class so it supports all the features, attributes of RelativeLayout and it has percentage dimensions so it also supports some features of LinearLayout. In Simple words we can say that PercentRelativeLayout has features of both Layouts with reduced view complexity.

What is the difference between percentage and relative layout?

PercentRelativeLayout is same as relative layout with an additional feature ‘percentage’. we can put percentage on view component (out of 100) in terms of width,height,margins etc. Or simply we can say use relative percent layout as linear layout as it has features of both along with reduced view complexity.

How to add percentage based dimensions and margins in relativelayout?

Subclass of RelativeLayout that supports percentage based dimensions and margins. You can specify dimension or a margin of child by using attributes with "Percent" suffix. Follow this example: layout_marginBottomPercent

What is the best option for the performance of a layout?

View centered in another view. If we have to use that view, the best option is FrameLayout. This example also shows that if we can use the simplest layout it’s the best option for our performance. 3. Layout with 2 views on different sides.


2 Answers

Looking at the source code, a PercentRelativeLayout is basically a minor extension of a RelativeLayout. This means you need to make the same considerations as when you choose between a RelativeLayout and LinearLayout.

  • RelativeLayout needs 2 measure passes -> avoid using it as the root of a deep view hierarchy or nesting multiple RelativeLayouts (more info in this stackoverflow post)
  • Layout weights in LinearLayout also require 2 measure passes -> try to replace these constructs as much as possible with one Relative/GridLayout (more info in this stackoverflow post)

Finally it is worth noting that:

  • Don't optimise unless you have a problem
  • Try to keep your hierarchies as flat as possible
like image 92
Jeroen Mols Avatar answered Oct 18 '22 21:10

Jeroen Mols


PercentRelativeLayout 

is just a extension of RelativeLayout so i think:

1) u should use it in case of nested weights with linearlayout as they are bad for performance

2)No,but depends on your useCase. For ex:-it has less performance than LinearLayout and RelativeLayout but more than LinearLayout with nested weight

Also u can refer this post from android developer: http://developer.android.com/training/improving-layouts/optimizing-layout.html

like image 1
JAAD Avatar answered Oct 18 '22 20:10

JAAD