0

I have a grid view and i want 10 buttons in a row. What should be the size of the buttons to fit exactly 10 buttons in width. If i take in mm or in it would work for only one type of screen. Any tips on how to use dp or dip is appreciable .

Prithvi Raj
  • 1,611
  • 1
  • 14
  • 33
  • you should dynamically calculate it as screen size / 10, and do it before populating the GridView. Also you can try to set the `android:numColumns="2"` attribute of the GridView, and set the views width to `match_parent` – Vladyslav Matviienko Jun 16 '17 at 11:30
  • Thanks! but how can i get the value of Screen size dynamically? – Prithvi Raj Jun 16 '17 at 11:32
  • i want the size to be static...like using "dp" – Prithvi Raj Jun 16 '17 at 11:38
  • 1
    How about using a horizontal linearLayout? You can set its weightSum attribute to 10, and then set a weight of 1 on each button. They will all have the same size, and will fit on a row. – k3v1n4ud3 Jun 16 '17 at 11:38
  • there is no way for it to be *static* on *dynamical* size of the screen (for different devices). dp is not what you think, it is dynamical too. – Vladyslav Matviienko Jun 16 '17 at 11:47

1 Answers1

0

With each screen having different sizes you would need to base it on the size of the screen loading the app. I think this link may help you there.

In addition, to better understand dp or Density-independent pixels, you may want to look here for the equation of a dp and using them in a layout of an application.

Hope this helps.

Gazza732
  • 169
  • 3
  • 15