Search code examples
androidandroid-linearlayoutandroid-relativelayoutandroid-constraintlayout

How to know how much time take for loading layout in android?


I want to check which layout is loading fast with the same design like Relative Layout, Linear Layout or Constraint Layout but I can't get any tool or any idea about that so please help me out for my query.

Thanks in Advance.


Solution

  • I think this trick may help you.

    long time1 = System.currentTimeMillis();
    
    setContentView(R.layout.activity_main);
    
    long time2 = System.currentTimeMillis();
    
    Log.i(TAG, "onCreate: " + (time2 - time1));
    

    My results for empty parent layout:

    ConstraintLayout: 74ms

    RelativeLayout: 54ms

    LinearLayout: 55ms

    FrameLayout: 57ms

    Have tested in Huawei Nexus 6P. Maybe these results will be different, when these layouts draw multiply views, but RelativeLayout is leading for empty layouts.