1

I'm tyring use FrameLayout with Multiple children within it. I know by using android:layout_gravity attribute I can add multiple children to a FrameLayout. But my unclear part is whether it is affecting to the performance side and Cost side of the app if I add more Children to the FrameLayout

Udara Abeythilake
  • 1,215
  • 1
  • 20
  • 31

2 Answers2

4

roughly 80 is the limit.

you will get following lint when you have too many view in your layout

AndroidLintTooManyViews

Description

Layout has too many views Using too many views in a single layout is bad for performance. Consider using compound drawables or other tricks for reducing the number of views in this layout. The maximum view count defaults to 80 but can be configured with the environment variable ANDROID_LINT_MAX_VIEW_COUNT.

note that limitation my differ cross different devices as performance score for different devices vary.

alireza easazade
  • 3,324
  • 4
  • 27
  • 35
2

What is the maximum number of Children Views inside a FrameLayout in Android?

There's no limit indicated on how many children that a ViewGroup can have on the docs. But you should try to lessen it as much as possible because it will take too long to render and it may cause your app to crash, throwing OutOfMemoryException or StackOverflowException. It was also indicated here.

whether it is affecting to the performance side and Cost side of the app if I add more Children to the FrameLayout

Adding more views will surely takes more time to load than having less views. The proper question I guess is, what's the efficient way to render views? Nesting views are inefficient, you should always try to avoid deep hierarchy as much as possible and you can achieve this by using ConstraintLayout. You can read more about optimizing view hierarchies here.

Tenten Ponce
  • 2,436
  • 1
  • 13
  • 40