Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

What about this ?

android:layout_width="1in"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top