[英]Font size for different density devices
When I tested the font size with different density settings using the Eclipse Emulator, I get different size fonts even though I am using "dp" to specific the size. 当我使用Eclipse Emulator测试不同密度设置的字体大小时,即使我使用“dp”来指定大小,我也会得到不同大小的字体。 I would have thought the size may decrease with higher density, but I found the higher the density, the bigger the font is. 我原本认为尺寸可能随着密度的增加而减小,但我发现密度越高,字体越大。 I tried using "in" and "mm" and the same behavior occurs, in that the higher density, the bigger the fonts. 我尝试使用“in”和“mm”并且出现相同的行为,因为密度越高,字体越大。 This is based on android:minSdkVersion="10". 这是基于android:minSdkVersion =“10”。
Is there any way I can set the font sizes to scale to the same size for the different density? 有什么办法可以设置字体大小以扩大到不同密度的相同大小?
Here is the xml file: 这是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>
Unfortunately I cannot post the images of the font size for the three Emulator settings due to lack of reputation. 遗憾的是,由于缺乏声誉,我无法发布三个模拟器设置的字体大小的图像。
Thank you. 谢谢。
Use sp instead of dp 使用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>
我有同样的问题...并没有找到任何东西,但没有找到任何东西,但制作文件夹:布局 - 小...大,xlarge,文件夹与高,中,小密度的可绘制图像与根据它的图像resolutios ..所以,一切都适用于不同屏幕的不同机器人......对于每个显示器尺寸,都有不同含义的dp布局...((
I guess one way is this: 我想有一种方法是这样的:
When you make new layout file there is next button in eclipse. 当您创建新的布局文件时,eclipse中有下一个按钮。 Press that and there is a list where to pick layout's density. 按下那个,有一个列表可以选择布局的密度。 You can pick x-high density, high density, medium density etc.. When you press finish it makes layout folder like "layout-hdpi" (depends what density you pick). 您可以选择x高密度,高密度,中密度等。当您按完成时,它会使布局文件夹像“layout-hdpi”(取决于您选择的密度)。 And then make text fit good with that density. 然后使文本适合该密度。
Hope that helps. 希望有所帮助。 :) :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.