Why is 1px sometimes 2px when specified in Android XML?

I have a desire for a single-pixel dividing line, just for looks. I thought I could accomplish this using a 1px height view with a specific background. However, I get very strange behavior on different devices - sometimes 1px ends up as 2px.

Take this sample circuit, 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 you start my G1, it turns out fine . But on the Nexus One, it alternates between 1px lines and 2px lines .

Does anyone know where this is happening? Why does Android sometimes do 1px to 2px?

: , , , , ; , , " 1px ", , .

+3
3

SDK 1.5 : anyDensity = "false"? , , Android , mdpi, . hdpi, Droid, 1,5x, "" .

, px dp .

+8

, , ; , dp (-) ? dp/pixel, ( dps) .

4px 4dp.

+1

, , ListView, :

android:divider="" /*color, drawable, etc*/
android:dividerHeight="1dip"

, , .

0

Source: https://habr.com/ru/post/1742476/


All Articles