title: Scrollable LinearLayout height limitation
body: <p>I am adding TextViews in a LinearLayout programmatically and I want to ensure that if the TextViews exceed a certain number the user will be able to scroll down. I included the LinearLayout inside a ScrollView which works fine up to a certain limit. After that limit, the top views are not shown at all. </p>
  
  <p>I am using the following code:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.linear_layout_with_scrollview);
  
  
      for (int i = 0; i &lt; 500; i++) {
          createView(String.valueOf(i));
      }
  }
  
  
  
  private void createView(String text){
  
      TextView tv = new TextView(this);
  
      LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
          LinearLayout.LayoutParams.WRAP_CONTENT,
          LinearLayout.LayoutParams.WRAP_CONTENT);
  
      lp.setMargins(0,15,0,0);
  
  
      tv.setLayoutParams(lp);
  
      tv.setText(text);
      tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP,20);
      LinearLayout layout=findViewById(R.id.linear_layout);
      layout.addView(tv);
  
  }
  </code></pre>
  
  <p>and for the layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;ScrollView android:layout_height="wrap_content" android:layout_width="match_parent"
      xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/linear_layout"
      android:layout_gravity="center"
      android:gravity="center"
      android:orientation="vertical" 
      android:layout_width="match_parent"
      android:layout_height="wrap_content"&gt;
  &lt;/LinearLayout&gt;
  
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>This is not the actual code I am using but a simplified version to demonstrate the problem.</p>