2012-02-10 59 views
0

当我使用Eclipse模拟器测试不同密度设置的字体大小时,即使我使用“dp”来指定大小,我也会得到不同大小的字体。我会认为随着密度的增加,尺寸可能会减小,但我发现密度越高,字体越大。我尝试使用“in”和“mm”,并且发生相同的行为,因为密度越高,字体越大。这是基于android:minSdkVersion =“10”。不同密度设备的字体大小

有没有什么办法可以将字体大小设置为不同密度的相同大小?

下面是XML文件:

<?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="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="20dp" 
    android:layout_gravity="center" 
    android:textColor="@color/orange" 
    android:textStyle="bold" 
    android:text="THIS IS A TEST" 
    android:background="@color/white"/> 
</LinearLayout> 

不幸的是我不能发布的字体大小的图片,由于缺乏信誉的三个模拟器设置。

谢谢。

回答

1

我有同样的问题......而我以前不发现任何东西,但做的文件夹:布局小...大,超大,与绘制图像的文件夹对于高密度,中密度和小密度的图像根据它...因此,一切适用于不同的屏幕不同的机器人...对于每个显示器尺寸有不同的dp含义的布局...((

+1

我已决定使用values-hdpi,values-xdhpi来控制不同密度的字体大小。像你一样,我似乎找不到更简单的解决方案。 – 2012-02-18 04:47:23

1

使用SP,而不是DP

<?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="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="20sp" 
    android:layout_gravity="center" 
    android:textColor="@color/orange" 
    android:textStyle="bold" 
    android:text="THIS IS A TEST" 
    android:background="@color/white"/> 

</LinearLayout> 
+0

我也试过,字体大小随着密度的增加而增加。在我的情况下,它的行为与dp相同。这是仿真器的缩放问题还是设备的行为方式? – 2012-02-10 12:49:54

+2

也许你可以尝试引用xml文件中的值并将它们放在代表不同屏幕大小的文件中 http://developer.android.com/guide/topics/resources/providing-resources.html – FabianCook 2012-02-10 12:53:26

0

我想一种方法是这样的:

当你让新的l ayout文件中有eclipse中的下一个按钮。按下该按钮,就会有一个列表选择布局密度。您可以选择x高密度,高密度,中等密度等。当您按下完成后,它会使布局文件夹像“layout-hdpi”(取决于您选择的密度)。然后让文字适合该密度。

希望有所帮助。 :)