I'm setting up a layout, that I'm adding to (via a for-loop) based on a set of objects. The issue is if there are say 3 fields (columns), if the middle field has a longer text length in the first entry than the second... the middle field in the first one will consume a larger width, even if I've already defined a weightSum and a layout_weight for that center column. My question is, when dynamically adding rows like this, how can I ensure that they all end up being the exact same width, as defined in the XML?
Asked
Active
Viewed 90 times
2 Answers
1
Why don't you just set a fixed width?
As in
setWidth(int width)
EDIT:
The formula to convert px to dpi is:
truePixels = DIPs * (device DPI / 160)
Here take a look how to get screen dpi.
Docs about supporting multiple screens.

Community
- 1
- 1

Comic Sans MS Lover
- 1,729
- 5
- 26
- 52
-
Because my layout is specified using weight, so I don't get odd results on different sized device screens. If I set actual dimensions, it may cause layout issues on smaller screens, vs tablet screens – RyanInBinary Jul 05 '12 at 16:08
-
You can use DPI so it's compatible with different screens. – Comic Sans MS Lover Jul 05 '12 at 16:09
-
When you use setWidth is it looking for a dpi value? I thought it was in pixels – RyanInBinary Jul 05 '12 at 16:12
-
you can alwasy get the density screen and multiply the widht – Blackbelt Jul 05 '12 at 16:13
-
@RyanInBinary As stated by blackbelt, you can convert px to dpi. Take a look at the edit. – Comic Sans MS Lover Jul 05 '12 at 16:15
0
If you're using xml layout for rows then:
android:layout_width="0"
If everything is done programmatically then setWidth(0)

pawelzieba
- 16,082
- 3
- 46
- 72