Android Creating button dynamically and fill layout

前端 未结 6 1543
长情又很酷
长情又很酷 2021-01-01 05:25

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

6条回答
  •  粉色の甜心
    2021-01-01 05:49

    Well, you can try using more sophisticated way. You can create horizontal linear layout, and add buttons to it. Every time you're attempting to add new button, you check if there is place for it, by finding difference between layout's and buttons widths.

    Each time your horizontal layout is filled, you add it to another vertical layout, and create another horizontal layout to store buttons left.

    I used that trick in my apps.

提交回复
热议问题