0

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
StevenTB
  • 405
  • 5
  • 19
  • 1
    GridLayout. See [here](http://developer.android.com/reference/android/widget/GridLayout.html). With it setup you can adjust how much space a cell takes up and also implement an auto-fit algorithm with ease. – TheSunny Jan 21 '16 at 20:43
  • It seems to be the right way to do that. Thanks @TheSunny ! – StevenTB Jan 21 '16 at 20:52
  • I have put it as an answer, upvote and accept. Thanks. – TheSunny Jan 21 '16 at 21:03
  • 2
    I'd rather use a GridView than a GridLayout: http://developer.android.com/guide/topics/ui/layout/gridview.html – Floern Jan 21 '16 at 21:07
  • Using GridView with a custom Adapter looks like to be better – StevenTB Jan 21 '16 at 21:15

1 Answers1

1

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

TheSunny
  • 371
  • 4
  • 14