문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

What about this ?

android:layout_width="1in"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top