gpt4 book ai didi

android - 分辨率之间的字体大小差异

转载 作者:行者123 更新时间:2023-11-29 02:13:45 25 4
gpt4 key购买 nike

我在 240 hdpi WVGA800 上开发了我的应用程序。我的一些按钮上的文本大小太小,所以我不得不将它们更改为 50sp。它在我开发的平台上看起来不错,但在 120 ldpi QVGA 和 160 mdpi HVGA 上测试时,文本被略微截断。此外,在 3.0 上测试时,文本太小了。你如何处理这个问题?

编辑:它实际上只出现在 1 布局中。该布局具有嵌套的线性布局,权重为 1,因此每一行的大小都相等并填满屏幕。 LinearLayout 的 layout_weight,因此它可以垂直拉伸(stretch)以适应屏幕。并且对于每个按钮,它们都可以水平拉伸(stretch)以填满屏幕。

<LinearLayout>
<ViewFlipper>
<LinearLayout>
<LinearLayout android:layout_weight="1">
<Button android:layout_weight="1"></Button>
<Button android:layout_weight="1"></Button>
<Button android:layout_weight="1"></Button>
</LinearLayout>
<LinearLayout android:layout_weight="1">
<Button android:layout_weight="1"></Button>
<Button android:layout_weight="1"></Button>
<Button android:layout_weight="1"></Button>
</LinearLayout>
<LinearLayout android:layout_weight="1">
<Button android:layout_weight="1"></Button>
<Button android:layout_weight="1"></Button>
<Button android:layout_weight="1"></Button>
</LinearLayout>
<LinearLayout android:layout_weight="1">
<Button android:layout_weight="1"></Button>
<Button android:layout_weight="1"></Button>
<Button android:layout_weight="1"></Button>
</LinearLayout>
</LinearLayout>
<LinearLayout>
</LinearLayout>
</ViewFlipper>
</LinearLayout>

最佳答案

您需要使用“dp”设置您的文本大小 - 请参阅此处:http://developer.android.com/guide/practices/screens_support.html

密度无关像素 (dp)应用程序可用于定义其 UI 的虚拟像素单元,以与密度无关的方式表达布局尺寸或位置。

密度无关像素相当于 160 dpi 屏幕上的一个物理像素,这是平台假定的基线密度(如本文档后面所述)。在运行时,该平台根据所用屏幕的实际密度,透明地处理所需 dp 单位的任何缩放。 dp 单位到屏幕像素的转换很简单:pixels = dps * (density/160)。例如,在 240 dpi 屏幕上,1 dp 等于 1.5 个物理像素。强烈建议使用 dp 单位定义应用程序的 UI,以确保在不同屏幕上正确显示 UI。

关于android - 分辨率之间的字体大小差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5706003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com