Ryhan
Ryhan

Reputation: 1885

Performance: onCreateView vs dynamic loading

I'm at a point right now where a piece of my UI layout will be based on certain conditions. The layout is made of 2 portions. The upper half is fine. The lower half, however, I am debating between having a fragment wrapper container, within the view being set (setContentView), with a single fragment responsible of loading the correct lower half (onCreateView overriden).

For example, I may have 3 different XML layout files accounting for the different UI looks, and at run time the fragment would return the right one based on certain conditions. Or, I could not have 3 different XML layout files, and dynamically construct the necessary widgets in same layout file (currently, maximum of 4 ImageButtons) at runtime.

Choice 1: 3 different XML files + 1 Fragment to load the right one based on conditions.

Choice 2: Use the current layout file, and populate lower half dynamically.

Thanks in advance!

Upvotes: 0

Views: 296

Answers (1)

user
user

Reputation: 87064

Choice 1: 3 different XML files + 1 Fragment to load the right one based on conditions.

Choice 2: Use the current layout file, and populate lower half dynamically.

There isn't a clear choice from what you wrote. If you intend to change those layouts between them at runtime then you could choose fragments(a fragment for each of the layouts, to replace them more easily). If you'll be choosing a layout only when the layout is first constructed then simply make the decision at the Activity level and choose the appropriate layout file.

Or, I could not have 3 different XML layout files, and dynamically construct the necessary widgets in same layout file (currently, maximum of 4 ImageButtons) at runtime.

Doesn't matter, this will not make any real differences.

Upvotes: 1

Related Questions