Reputation: 11608
In my Activity
I have a complex View
structure since I have a lot of data to display. I've got many RelativeLayouts
with a lot of TextViews
. I've googled around but found no clear information about complex Layouts
and RAM usage.
So the question is: from the RAM usage point of view, does it matter if I use RelativeLayout
, LinearLayout
etc. or the RAM consumption is independent from Layout
type?
Upvotes: 1
Views: 679
Reputation: 7663
Two things (1) I don't think ram usage is the correct way to measure performance in this case. XML is pretty lightweight. I cannot image even complicated XML layouts using a lot of ram on the XML alone. Rather the components of the layout, e.g. Bitmaps, will be what uses the memory.
(2) I don't know that the type of layout matters so much as the complexity of that layout.
While I also do not have documentation to support this view I'm logicly thinking about how XML is parsed by the system. A simple RelativeLayout
or LinearLayout
should perform about the same. However, once you start nesting layout elements - as happens frequenty in LinearLayouts
- things are probably different. As the XML needs to be parsed for the system to understand what is going on, each layer of parsing that you add is likley to decrease performance. For example, a LinearLayout
set to vertical orientation with several sub-layouts to handle each "row" will take longer to render than one RelativeLayout
that positions elements next to each other.
In most situations I don't think you'd notice that big of a difference. For a single activity for example rending a complex layout once will not be that difficult. But think about a list or a grid view where, even with view recycling an XML structure has to be parsed as many times as it takes to fill the screen. That's where you will start to see things slow down.
Hope that helps.
Upvotes: 2