简体   繁体   English

为什么这些 dp 单位在同一个布局中渲染的厚度是原来的两倍?

[英]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.下面我有一些 xml 来生成一个可缩放的 fork 来生成排名阶梯。 This xml is used several times in the same layout.此 xml 在同一布局中多次使用。 However, the dp lines scaled with the screen height seem to randomly vary in actual pixel height when used.然而,随着屏幕高度缩放的 dp 线在使用时似乎在实际像素高度上随机变化。

Why is this?为什么是这样? Why would a 1dp height unit on the same screen return both 1 and 2px on the same device?为什么同一屏幕上的 1dp 高度单位会在同一设备上同时返回 1 和 2px?

<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.这是 Android 模拟器的渲染错误。 No issues were found on physical devices.在物理设备上没有发现问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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