0

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.

3 Answers 3

1

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

1
  • 1
    I have decided to use values-hdpi, values-xdhpi to control my font size for different densities. Like you, I cannot seem to find an easier solution. Feb 18, 2012 at 4:47
1

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>
2
  • I tried that as well and the font size increase as density increases. It behaves the same as dp in my case. Is this a scaling problem with the emulators or does the devices behave that way as well? Feb 10, 2012 at 12:49
  • 2
    Maybe you could try referencing values in a xml file and putting them in files which represent the different screen sizes developer.android.com/guide/topics/resources/…
    – FabianCook
    Feb 10, 2012 at 12:53
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.