Warning: This can be replaced with a tag

前端 未结 4 1951
陌清茗
陌清茗 2021-02-05 08:58

I have a FrameLayout that contains a TextView and two LinearLayouts:



        
4条回答
  •  野的像风
    2021-02-05 09:05

    To render the XML in the device a process is followed in phases, and the first one is Measure.

    Measure: In this phase, the sizes of the parent and their children and their children, and so on, is measured. So your CPU scans all the ViewGroup and View in your layout to measure their sizes. And sometimes for some reasons, it may require this scanning recursively because of the dependency of the size of the parent and their children on each other.

    So why Lint is giving this warning?

    Because your XML eventually will be loaded into a window which contains FrameLayout and in your XML file you are also using the FrameLayout, so eventually your XML will be placed in FrameLayout of the window and it will be like this:

     
         
                ...
        
    
    

    Now there is an overhead for CPU in the measure phase, to measure both the FrameLayout. And this overhead can be overcome if we can somehow manage to use the outer FrameLayout in our XML, that's exactly possible via merge tag.

提交回复
热议问题