繁体   English   中英

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

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

下面我有一些 xml 来生成一个可缩放的 fork 来生成排名阶梯。 此 xml 在同一布局中多次使用。 然而,随着屏幕高度缩放的 dp 线在使用时似乎在实际像素高度上随机变化。

为什么是这样? 为什么同一屏幕上的 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>

这是 Android 模拟器的渲染错误。 在物理设备上没有发现问题。

暂无
暂无

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

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