简体   繁体   中英

Why do these dp units render twice as thick in the same Layout?

Below I have some xml to generate a scale-able fork for generating ranking ladders. This xml is used several times in the same layout. However, the dp lines scaled with the screen height seem to randomly vary in actual pixel height when used.

Why is this? Why would a 1dp height unit on the same screen return both 1 and 2px on the same device?

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="50dp">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:orientation="horizontal">

        <View
            android:layout_width="8dp"
            android:layout_height="1dp"
            android:background="#e7000000"
            android:layout_gravity="center_vertical"/>

        <View
            android:layout_width="1dp"
            android:layout_height="30dp"
            android:background="#e7000000"
            android:layout_gravity="center_vertical"/>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:orientation="vertical">

            <View
                android:layout_width="8dp"
                android:layout_height="1dp"
                android:background="#e7000000"
                android:layout_marginTop="10dp"/>

            <View
                android:layout_width="8dp"
                android:layout_height="1dp"
                android:background="#e7000000"
                android:layout_marginTop="28dp"/>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

It's a rendering bug with the Android Emulator. No issues were found on physical devices.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM