0

I divide a LinearLayout into say 7 different Views using weight_sum = 7 and the Views each have layout_weight = 1. The whole LinearLayout spans over 100 pixels on the device.

100 pixels / 7 = 14.29 pixels. Since pixels can only be integers the actual size in pixels of the 7 child views will be like this:

14 - 14 - 14 - 14 - 14 - 15 - 15

I'm now wondering which formula Android uses to calculate where to round down and where to round up.

For positioning, I would need to know it for any LinearLayout of size x with y child views.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Christopher Masser
  • 809
  • 13
  • 25

2 Answers2

0

If you see in the source of LinearLayout you can see that it is using simple Math.Max function to do simple calculation like this. more related info you can find here

Community
  • 1
  • 1
Ali Imran
  • 8,927
  • 3
  • 39
  • 50
0

From the source code, it casts the division to an int. See line 441.

Therefore, it always takes the floor integer value

znat
  • 13,144
  • 17
  • 71
  • 106