Skip to main content

Posts

Showing posts with the label dynamically-generated

Android Creating button dynamically and fill layout

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 My code is like below: Button[] tv = new Button[arraylist.size()]; for(int i=0;i<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]); } If I set the orientation of linear layout to vertical the button will fill vertically. So if there any solution to create the button dynamical