StevenTB
StevenTB

Reputation: 410

Generate LinearLayout programmatically

I would like to generate some buttons items programmatically (I receive data from an API) following this mockup :

I don't know how many I will receive because it's dynamic

What is the best way to generate and populate them ? How can I use xml drawable files to be the most efficient ?

Currently, this following is how I will resolve this :

  1. count = number of items % 2
  2. if count != 0, number of lines equals (number_of_items/2)+1
  3. for each line I will create 2 buttons into the LinearLayout

Upvotes: 0

Views: 80

Answers (1)

TheSunny
TheSunny

Reputation: 381

GridLayout. See here. With it setup you can adjust how much space a cell takes up and also implement an auto-fit algorithm with ease

Upvotes: 1

Related Questions