Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I did some VERY informal/hackish tests on this, and found that taking the programmatic approach, whilst not as nice to work with, shaved between a third and a half of the total time taken. The test was run on a Samsung 7" Galaxy only, and not on an AVD.</p> <p>As I say this was a very informal/hackish test (as you'll see by the code), with very limited circumstances, the sort of thing you put together quickly to satisfy your own curiosity and not usually for public consumption.</p> <p>R.layout.ll and R.layout.tv are simple layout files containing blank LinearLayouts and TextViews respectively.</p> <p>If you're just working with a handful of views I'd stick with XML/inflaters, but for hundreds then maybe you'll want to consider the programmatic approach if speed is an issue.</p> <pre><code>package com.inflatervscode; import java.util.Calendar; import android.app.Activity; import android.os.Bundle; import android.widget.LinearLayout; import android.widget.TextView; public class InflaterVSCodeActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } // Generates a few nested LinearLayouts/TextViews, a number of // times, and works out how many milliseconds this took. @Override public void onResume() { super.onResume(); setContentView(R.layout.main); int num_repeats = 500; // Change this to however many times you want to // create a set of nested views. LinearLayout masterLL = (LinearLayout)findViewById(R.id.test); TextView results = (TextView)findViewById(R.id.results); Calendar c = Calendar.getInstance(); long startTime = c.getTimeInMillis(); for (int i=0;i&lt;num_repeats;i++) { // Replace the section below with LinearLayout fll = new LinearLayout(this); etc LinearLayout fll = (LinearLayout)getLayoutInflater().inflate(R.layout.ll, null); LinearLayout sll = (LinearLayout)getLayoutInflater().inflate(R.layout.ll, null); LinearLayout tll = (LinearLayout)getLayoutInflater().inflate(R.layout.ll, null); TextView tv = (TextView)getLayoutInflater().inflate(R.layout.tv, null); tv.setText(i+""); tll.addView(tv); sll.addView(tll); fll.addView(sll); masterLL.addView(fll); } c = Calendar.getInstance(); long endTime = c.getTimeInMillis(); String tt = Long.toString((endTime-startTime)); results.setText("Results for "+num_tests+" tests:\n\nStart:"+Long.toString(startTime)+"\nEnd :"+Long.toString(endTime)+"\n\nDifference (ms):"+tt); } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload