简体   繁体   中英

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. 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.

Use sp instead of 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. 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. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM