在不同设备上使文本大小相同

4
我想知道如何在不同设备上使应用程序看起来相同。我已经多次阅读支持多个屏幕,但我仍然不明白如何实现。
这是一个示例布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        >
    <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Hello World, MyActivity"
            android:textSize="30sp"
            />
</LinearLayout>

有Galaxy S II(480x800)和Sensation XE(540x960)。它们都是hdpi,物理屏幕大小几乎相同。我期望在两个设备上看到相同的外观,但实际上,540x960上的文本比480x800上的文本小: enter image description here (左边是480x800,右边是540x960)
我尝试将文本大小指定为维度资源,并创建单独的文件夹values-w540dp,但没有效果。
你们如何让应用程序在不同的hdpi设备上看起来相同?

从技术上讲,这两件事是相等的。它可以使文本大小相同,但无法使较小的屏幕变宽 :) 请注意,“Hello”在“Demo”的结尾大致相同的位置结束。 - Bill Mote
3个回答

3
android:textAppearance="?android:attr/textAppearanceLarge"

android:textAppearance="?android:attr/textAppearanceMedium"

android:textAppearance="?android:attr/textAppearanceSmall"

这些属性可能会解决您的问题,否则您需要使用一些比例(或因子,例如:textSize = factor * height)根据您的屏幕高度和宽度动态设置布局。

0

看一下指标,如果你在dp(密度无关像素)中指定了文本大小,它应该可以工作。文本的默认大小应该大约为14dp。(TextAppearance.small)


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接