2012-02-10 60 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」(取決於您選擇的密度)。然後讓文字適合該密度。

希望有所幫助。 :)