Should I create child text images statically or dynamically?

I have a list in which elements contain a different number of text views for children.

min 5 max 20 

I tried in both directions and I only have vm to test my applications, so I can’t say what the difference is in performance. Wise.

but what is the best way to do this?

Should I create 20 text views in my xml and just hide the ones I don't use? or just create and add new text images every time, resulting in no "Ghost views"

-1
source share
1 answer

Problems for implementation:

  • Code cleanliness - Doing anything more than the basic layouts in your code can become very dirty, very fast.

  • Reusing code -> Its extremely easy to inflate an XML layout into a specified view with one or two lines of code

  • Code performance β†’ Creating the objects necessary for compilation in the code leads to unnecessary garbage collection. According to Android Designing for Performance, "Avoid creating short-term temporary objects if you can."

  • Attribute Availability β†’ Defining Views in an XML Layout provides attributes that are not always accessible by object methods.

Possible disadvantages:

It will take longer to create the XML layout and define the layout in the code, especially if there is only one or two interface elements that need to be changed.

After thinking about what I want to achieve, it makes sense for me to use XML layouts for changing dynamic changes. It would be more than just a few lines of code to execute my layout changes without using XML layouts.

Now you can decide according to your requirements.

-2
source

Source: https://habr.com/ru/post/1387548/


All Articles