不同密度设备的字体大小
当我使用 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>
不幸的是,由于缺乏声誉,我无法发布三个模拟器设置的字体大小图像。
谢谢。
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. 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. This is based on 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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了同样的问题...并且没有找到任何东西,但是制作文件夹:布局小...大,xlarge,以及带有可绘制图像的文件夹,用于高,中,小密度,并根据其图像分辨率..因此,在具有不同屏幕的不同机器人上,一切都运行良好...对于每种显示尺寸,都有不同含义的 dp 布局...((
I had the same problem... And did't found anything, but making folders:layout-small...large, xlarge, and folders with drawable images for high, mid and small densities with resolutios of images according to it... So, everything works well on different droids with different screens... For every display size there is layout with different meanings of dp...((
使用sp代替dp
Use sp instead of dp
我想一种方法是这样的:
当你创建新的布局文件时,Eclipse 中有一个下一个按钮。按下它,就会出现一个列表,可以在其中选择布局的密度。您可以选择 x-高密度、高密度、中密度等。当您按“完成”时,它会生成类似“layout-hdpi”的布局文件夹(取决于您选择的密度)。然后使文本适合该密度。
希望有帮助。 :)
I guess one way is this:
When you make new layout file there is next button in 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). And then make text fit good with that density.
Hope that helps. :)