1

This one is bedeviling me. What am I overlooking? I want a button exactly one inch wide, on any density screen. I declare it in the layout like this:

<Button  
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:width="160dip"
android:text="How wide?"
/>

What I get is a button that is exactly 7/8ths of an inch wide on all screens, not the expected 1 inch. Is the difference maybe the margin or padding around the button? If so, how to set that to zero?

Peter vdL
  • 4,953
  • 10
  • 40
  • 60

2 Answers2

4

What about this ?

android:layout_width="1in"
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
3

dip are based on virtual densities, not actual physical densities. For instance, on a T-Mobile G1, the device's display physical density is around 180dpi, but we treat it as a 160dpi display. Android currently uses 3 "density buckets," 120, 160 and 240. Each device uses whatever is most appropriate. If you want accurate physical measurements, use physical units like in, mm, etc.

Romain Guy
  • 97,993
  • 18
  • 219
  • 200
  • True, but also it seems there is always some empty spacing around a button, even if you set the margin and padding to 0. If you compare it with an ImageView you will see the difference. – Niels Nov 30 '12 at 11:16