title: Add Image in next line in LinearLayout Programatcally - Android
body: <p>I have a LinearLayout with orientation horizontal, but when it cross 4 elements in an one row it keeps adding in horizontal, I want to it automatically changes to the next row, example:</p>
  
  <p>What happens:
  <a href="https://i.stack.imgur.com/husyj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/husyj.png" alt="Whta happen:"></a></p>
  
  <p>What I want:
  <a href="https://i.stack.imgur.com/Cv7JZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Cv7JZ.png" alt="What I want:"></a></p>
  
  <p>My code:</p>
  
  <pre><code>btnAdd.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              countLikesAdd++;
              removeMessageOrShow();
              ImageView iconLike = new ImageView(Register30.this);
              iconLike.setImageDrawable(getDrawable(R.drawable.musicicon));
              LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(140,130);
              lp.setMargins(5,5,5,5);
              iconLike.setLayoutParams(lp);
              relativeLayout.addView(iconLike);
          }
      });
  </code></pre>
  
  <p>My XML:</p>
  
  <pre><code>&lt;ScrollView
      android:id="@+id/svLikes"
      android:layout_width="0dp"
      android:layout_height="0dp"
      android:layout_marginBottom="60dp"
      android:layout_marginEnd="14dp"
      android:layout_marginStart="14dp"
      android:layout_marginTop="48dp"
      android:background="#2f3342"
      android:orientation="vertical"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toTopOf="@+id/btnAdd"
      app:layout_constraintVertical_bias="0.0"
      tools:layout_constraintBottom_creator="1"
      tools:layout_constraintLeft_creator="1"
      tools:layout_constraintRight_creator="1"
      tools:layout_constraintTop_creator="1"&gt;
      &lt;LinearLayout
          android:id="@+id/linearLayout"
          android:orientation="horizontal"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:padding="5dp"
          android:paddingEnd="5dp"
          android:paddingTop="5dp"
          android:paddingLeft="5dp"
          android:paddingRight="5dp"
          &gt;
      &lt;/LinearLayout&gt;
  &lt;/ScrollView&gt;
  </code></pre>