title: How to fit a LinearLayout in a ScrollView?
body: <p>Earlier on I asked a question <a href="https://stackoverflow.com/questions/60510336/how-to-reach-the-last-items-of-a-scroll-view/60510966#60510966">about how to reach the last item of a scrollview</a> and someone pointed out that I should be using NestedScrollView, at first it worked but now it's not what I want.</p>
  <p>I want to fit my list of item in the ScrollView so only that part of the screen can be scrolled and the other parts stay at their place (the 3 TextView)<br />
  <a href="https://i.stack.imgur.com/HfsWj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HfsWj.png" alt="frame design" /></a></p>
  <p>So basically my xml file is like this :</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:id=&quot;@+id/cl_framgnent_detail_apero&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:background=&quot;@color/colorPrimary&quot;
      tools:context=&quot;.ui.home.AperoDetailFragment&quot;&gt;
  
      &lt;TextView
          android:id=&quot;@+id/name_apero&quot;
           /&gt;
  
      &lt;TextView
          android:id=&quot;@+id/date_apero&quot;
           /&gt;
  
      &lt;TextView
          android:id=&quot;@+id/ingredient_title_apero&quot;
           /&gt;
  
      &lt;ScrollView
          android:id=&quot;@+id/rv_apero_ingredient&quot;
          android:layout_width=&quot;408dp&quot;
          android:layout_height=&quot;603dp&quot;
          android:fillViewport=&quot;true&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;@+id/ingredient_title_apero&quot;
          app:layout_constraintHorizontal_bias=&quot;0.0&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@+id/ingredient_title_apero&quot;
          app:layout_constraintVertical_bias=&quot;1.0&quot;&gt;
  
          &lt;LinearLayout
              android:id=&quot;@+id/vertical_layout_ingredient&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:orientation=&quot;vertical&quot; /&gt;
      &lt;/ScrollView&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p>And in my Java code I try to populate my list with the following code :</p>
  <pre class="lang-java prettyprint-override"><code>public class AperoDetailFragment extends Fragment {
  
      private View root;
      private Apero detailApero;
  
      public AperoDetailFragment(Apero apero) {
          this.detailApero = apero;
      }
  
      @Override
      public View onCreateView(@NonNull final LayoutInflater inflater,
                               final ViewGroup container, Bundle savedInstanceState) {
          root = inflater.inflate(R.layout.fragment_detail_apero, container, false);
  
          TextView name = (TextView) root.findViewById(R.id.name_apero);
          name.setText(detailApero.getName());
          TextView date = (TextView) root.findViewById(R.id.date_apero);
          date.setText(detailApero.getDate());
  
          LinearLayout ll = (LinearLayout) root.findViewById(R.id.vertical_layout_ingredient);
          LinearLayout a = new LinearLayout(root.getContext());
          ConstraintLayout.LayoutParams lparams = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.MATCH_PARENT);
          a.setLayoutParams(lparams);
  
          a.setOrientation(LinearLayout.VERTICAL);
          for (int i = 0; i &lt; 20; i++) {
              Button b = new Button(root.getContext());
              b.setText(&quot;Button &quot; + i);
              a.addView(b);
          }
          ll.addView(a);
  
          return root;
      }
  }
  </code></pre>
  <p>The problem is that the item are covering the whole screen instead of staying in the parent container (ScrollView) :</p>
  <p><a href="https://i.stack.imgur.com/iMJvP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iMJvP.png" alt="real view" /></a></p>
  <p>How can I fit my list of item to stay in the parent ?</p>