Why is 1px sometimes 2px when specified in Android XML?
- by Daniel Lew
I've got a desire for a one-pixel divider line, just for looks. I thought I could accomplish this using a View of height 1px, with a defined background. However, I'm getting some very odd behavior on different devices - sometimes the 1px ends up as 2px.
Take this sample layout for example:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<View android:layout_width="fill_parent" android:layout_height="1px"
android:background="@android:color/white" android:layout_marginBottom="4dp" />
<View android:layout_width="fill_parent" android:layout_height="1px"
android:background="@android:color/white" android:layout_marginBottom="4dp" />
<View android:layout_width="fill_parent" android:layout_height="1px"
android:background="@android:color/white" android:layout_marginBottom="4dp" />
<View android:layout_width="fill_parent" android:layout_height="1px"
android:background="@android:color/white" android:layout_marginBottom="4dp" />
<View android:layout_width="fill_parent" android:layout_height="1px"
android:background="@android:color/white" android:layout_marginBottom="4dp" />
<View android:layout_width="fill_parent" android:layout_height="1px"
android:background="@android:color/white" android:layout_marginBottom="4dp" />
<View android:layout_width="fill_parent" android:layout_height="1px"
android:background="@android:color/white" android:layout_marginBottom="4dp" />
</LinearLayout>
When run on my G1, this comes out fine. But on the Nexus One, it alternates between 1px lines and 2px lines.
Does anyone know where this is going awry? Why does Android sometimes make 1px into 2px?