title: Android - Make a ScrollView with LinearLayout
body: <p>I want to make a ScrollView with a LinearLayout inside. The linear layout contains 6 View that have the background CYAN, BLUE, CYAN, BLUE etc...  This is the code:</p>
  
  <pre><code>public class TouchActivity extends Activity
  {
      TouchedView TouchView;
  
      public void onCreate(Bundle icicle) 
      {
          super.onCreate(icicle);
  
          TouchView = new TouchedView(this);
          TouchView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT , LayoutParams.WRAP_CONTENT) );
  
          //setContentView(TouchView);
          setContentView(TouchView.ViewLayout);
      }
  
      class TouchedView extends ScrollView
      {
          LinearLayout ViewLayout;
          ListElement Elem1;
          ListElement Elem2;
          ListElement Elem3;
          ListElement Elem4;
          ListElement Elem5;
          ListElement Elem6;
  
  
          public TouchedView(Context context) 
          {
              super(context);
  
              ViewLayout = new TableLayout(TouchActivity.this);
              ViewLayout.setOrientation(LinearLayout.VERTICAL);
  
              Elem1 = new ListElement(TouchActivity.this , "CYAN");
              Elem1.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT , 100 ) );
              Elem2 = new ListElement(TouchActivity.this , "BLUE");
              Elem2.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT , 100 ) );
              Elem3 = new ListElement(TouchActivity.this , "CYAN");
              Elem3.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT , 100 ) );
              Elem4 = new ListElement(TouchActivity.this , "BLUE");
              Elem4.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT , 100 ) );
              Elem5 = new ListElement(TouchActivity.this , "CYAN");
              Elem5.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT , 100 ) );
              Elem6 = new ListElement(TouchActivity.this , "BLUE");
              Elem6.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT , 100 ) );
  
              ViewLayout.addView(Elem1);
              ViewLayout.addView(Elem2);
              ViewLayout.addView(Elem3);
              ViewLayout.addView(Elem4);
              ViewLayout.addView(Elem5);
              ViewLayout.addView(Elem6);
  
              setFillViewport(false);
              setContentView(ViewLayout);
  
          }
  
      }
  
  
      class ListElement extends View
      {
          public ListElement(Context context , String TypeName) 
          {
              super(context);
  
              if(TypeName.compareTo("CYAN") == 0) this.setBackgroundColor(Color.CYAN);
  
              if(TypeName.compareTo("BLUE") == 0) this.setBackgroundColor(Color.BLUE);    
          }
      }
  }
  </code></pre>
  
  <p>The result is that the 6 view are too big to be contained in the LinearLayout:</p>
  
  <p><a href="http://img513.imageshack.us/img513/5406/androidbadscrollview2.jpg" rel="nofollow">http://img513.imageshack.us/img513/5406/androidbadscrollview2.jpg</a></p>
  
  <p>But if I comment <code>setContentView(TouchView.ViewLayout);</code> and I uncomment <code>//setContentView(TouchView);</code>  my activity should be filled with the ScrollView instead of the <code>LinearLayout</code> but unfortunately I can't see anything.</p>
  
  <p>Note that the <code>ScrollView</code> contains the <code>LinearLayout</code> that is set by <code>setContentView(ViewLayout);</code></p>