2014-07-03 48 views
0

由於我有一個Nexus 5,我看到有關文字大小的奇怪東西。文字大小不同的Android手機

一個例子:我正在創建listview項目。我在22sp放了一個更大的文本,17sp放一個較小的文本。

在我的HTC One X,它看起來像這樣:

enter image description here

所以我覺得 「OK,這很好!」

然後,我在我的Nexus 5的運行它:

enter image description here

我不明白爲什麼會這樣? 「sp」部分不應該確保它看起來不錯 使用默認值?我不是在談論增加設置中字體大小的用戶,我已經將所有內容都設置爲默認值。如果我願意(不要打我)在這裏使用DP來禁用字體大小的文本變化,它會給出相同的結果(未測試,但我相當肯定這是從其他測試的情況下, )。

這裏有什麼問題嗎?它是較新的Android版本,還是1080p屏幕與720p?

我應該使用「值」文件夾爲不同的DP值使用不同的值嗎?

這裏是德佈局:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="80dp" 
    android:orientation="horizontal"> 

    <LinearLayout 
     android:id="@+id/background" 
     android:layout_marginTop="10dp" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal"> 

     <com.android.volley.toolbox.NetworkImageView 
      android:id="@+id/image" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:adjustViewBounds="true" 
      android:scaleType="centerCrop" /> 

     <RelativeLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_margin="5dp" 
      android:layout_weight="2"> 

      <ImageView 
       android:id="@+id/arrow" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_alignParentRight="true" 
       android:adjustViewBounds="true" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="3dp" 
       android:layout_toLeftOf="@id/arrow" 
       android:gravity="center" 
       android:orientation="vertical"> 

       <TextView 
        android:id="@+id/name" 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="1" 
        android:fontFamily="sans-serif-condensed" 
        android:textSize="22sp" 
        android:textStyle="bold" /> 

       <TextView 
        android:id="@+id/address" 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="1" 
        android:textSize="17sp" /> 
      </LinearLayout> 
     </RelativeLayout> 
    </LinearLayout> 
</LinearLayout> 

回答

1

例如,對於相同的SP值默認的大小可能會因設備而異,只是爲了匹配其可讀性設計的設備。

你得到的問題是因爲你有一些尺寸固定的元素,發佈你用於行的XML代碼,我們可以做一個深入的分析。

編輯 - XML

好,而不是點你的過錯,我也寧願重建佈局後,我們來看一看:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="10dp" 
    android:orientation="horizontal" > 

    <com.android.volley.toolbox.NetworkImageView 
     android:id="@+id/image" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" /> 

    <TextView 
     android:id="@+id/name" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@id/image" 
     android:layout_toLeftOf="@+id/arrow" 
     android:fontFamily="sans-serif-condensed" 
     android:textSize="22sp" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/address" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@id/image" 
     android:layout_toLeftOf="@id/arrow" 
     android:layout_below="@id/name" 
     android:textSize="17sp" /> 

    <ImageView 
     android:id="@id/arrow" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_alignParentRight="true" /> 
</RelativeLayout> 

您的佈局太複雜,簡單的一行...現在佈局將與TextViews需要的一樣高,並且這不是問題,因爲用戶已經使用了他的文本大小。

+0

添加了佈局。我預計'保證金'是原因 – Boy

+0

我實際上試圖避免相對佈局,因爲我認爲這會比'使用線性佈局'花費更多' – Boy

+1

如果您不使用重量,LinearLayouts速度很快,否則會變得非常昂貴。 –

0

您必須創建兩個不同的佈局文件夾並查看結果

+0

如果您創建真正可重新定義的佈局,並且即使您想按維度指定,也不是非常必要,但我建議您使用指定的樣式而不是佈局。 –