2

I was under the impression that 'dip' (Density Independent Pixel) values were the android solution to using % values to determine the width and height of layout elements. I thought this was an upgrade to using static 'px' (pixel) values or other static measurements like centimeter or inch.

Unfortunately dip values do not scale like a percentage value would, is there anything like percentage values with width and height parameters in Android?

Insight appreciated!

CQM
  • 42,592
  • 75
  • 224
  • 366

3 Answers3

5

Something like this might work:

 android:layout_weight=".70" 

So that would be 70% of the space.

You would just add it to whichever value you want, like a button or textbox or something

James
  • 5,622
  • 9
  • 34
  • 42
  • What do you mean "doesn't accept floats"? I'm working on a project now that has "android:layout_weight=".5" in the layout for a button, and the button takes exactly 50% of the view. – DeeV Jul 28 '11 at 15:22
  • you're wrong! it accepts floats, not sure until which digit after the coma, but at least the first digit after the coma is accepted! – nenito Jul 28 '11 at 15:27
  • `error: Error: Float types not allowed (at 'layout_width' with value '.7').` Did this on a linearlayout right now in the XML file, that is what the error said, and I am using Android 3.0 for this tablet only app – CQM Jul 28 '11 at 15:36
  • How is the -1? Even is this is something that cant be used on Android 3.0, you never specified that you where using that in the question.... – James Jul 28 '11 at 16:06
  • from my understanding, even deprecated functions are forward compatible so far, so I didn't feel that I needed to specify. Can you post a working XML example using those floats values? – CQM Jul 28 '11 at 16:29
  • 3
    I'd just like to specify that your error posted above says "layout_width" and they're saying use "layout_weight" .. similar, but not the same. :) That could be why you're getting an error. – Joishi Bodio Jul 28 '11 at 17:06
  • thanks, I definitely did not notice that! everyone should rank him up – CQM Jul 28 '11 at 18:47
1

As far as I know, the only way to do this is programmatically or by using layout_weight

See this link for info on layout_weight

Community
  • 1
  • 1
Austin Hanson
  • 21,820
  • 6
  • 35
  • 41
  • I'll give it a shot, I didn't realize layout_weight was accompanied by layout_sum in the parent node – CQM Jul 28 '11 at 16:34
0

I had that same issue, but could not find an answer, so I switched to doing everything progmatically instead of within XML.. That's the only insight I can offer you. :P Sorry! In response to the other answer .. I never tried layout_weight.. Only layout_width and layout_height.. But if you're trying layout_weight and it doesn't accept floats, it might be a different ADK level. (I'm programming on ADK 7)

Joishi Bodio
  • 438
  • 6
  • 17
  • I'm using Android 3.0 so there shouldn't really be any limitations with known Android issues at this point – CQM Jul 28 '11 at 16:35