0

我测试了模拟器和真实设备,但正如你所见,40 dp 和 40.2 dp 之间没有变化!我正在开发一个字体敏感度非常高的项目,问题是 android 文本引擎的行为。

有什么办法可以防止这种情况发生吗?

请帮忙!

这是代码:

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="SAMPLE TEXT"
            android:textSize="40dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="SAMPLE TEXT"
            android:textSize="40.2dp" />

    </LinearLayout>

结果:

4

2 回答 2

0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="SAMPLE TEXT"
    android:textSize="40sp" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="SAMPLE TEXT"
    android:textSize="40.2sp" />

你可以看到这样的区别(在android studio中你需要缩放布局屏幕)。android文本引擎没有行为问题。

在此处输入图像描述

于 2017-07-18T10:13:48.277 回答
0

您应该始终将 SP 用于字体,因为它尊重用户偏好

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SAMPLE TEXT"
        android:textSize="40sp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SAMPLE TEXT"
        android:textSize="40.2sp" />
于 2017-07-18T09:47:16.247 回答