I am trying to create a series of Buttons inside a LinearLayout. So I have the following code
XML
<LinearLayout
android:id="@+id/yearContainer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
in my Activity
LinearLayout yearContainer=(LinearLayout)findViewById(R.id.yearContainer);
for(int i=0;i<16;i++){
Button btn=new Button(this);
btn.setText("Button "+i);
btn.setId(150+i);
LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(width/3,LayoutParams.WRAP_CONTENT);
btn.setLayoutParams(params);
yearContainer.addView(btn);
}
But the Buttons are arranging vertically. I need it as the following pattern.

I am new to android. Please advise
Thanks in advance