title: Android Creating button dynamically and fill layout
body: <p>I'm creating a button dynamically. The number of button is depend on the size of arraylist. the problem is, after creating the button I will add to the layout using addview method. The problem is I'm using linear layout, as by default orientation for linear layout is horizontal, so the button will fill the layout horizontally. Because of that some of the button is not visible. What I'm trying to achieve is something look like this </p>
  
  <p><img src="https://i.stack.imgur.com/RcuL6.jpg" alt="multiple button in android messaging contact"></p>
  
  <p>My code is like below:</p>
  
  <pre><code>Button[] tv = new Button[arraylist.size()];
  for(int i=0;i&lt;arraylist.size();i++){                                
      tv[i] = new Button(getApplicationContext());
      tv[i].setText(arraylist.get(i).toString());
      tv[i].setTextColor(Color.parseColor("#000000"));
      tv[i].setTextSize(20);
      tv[i].setPadding(15, 5, 15, 5);     
      linearlayout.addView(tv[i]);    
  }
  </code></pre>
  
  <p>If I set the orientation of linear layout to vertical the button will fill vertically. So if there any solution to create the button dynamically  and fill the layout both horizontal and vertical as shown by image.</p>