android - 为什么这些 dp 单位在同一个 Layout 中呈现两倍的厚度?

标签 android android-layout

下面我有一些 xml 来生成一个可缩放的分支,用于生成排名阶梯。此 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 模拟器的渲染错误。在物理设备上未发现任何问题。

关于android - 为什么这些 dp 单位在同一个 Layout 中呈现两倍的厚度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52212778/

相关文章:

java - Firebase 与 Room 持久性库

android - 深层链接 Intent 过滤器到特定的路径前缀?

android - 多次使用复合组件时在屏幕旋转时保存状态

android - 区分 galaxy S3 和 galaxy Note 的设计布局

android - ScrollView 中的 ListView 在 Android 上不滚动

android - ArrayAdapter 中 ListView 第一行的不同布局

android - 如何为不同密度的屏幕指定图标?

android - 在android可绘制中调整图像大小

Android:Row.xml 的相对布局

android - TravisCI 无法测试构建,因为它使用 Android SDK