2014-07-03 47 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

如果您创建真正可重新定义的布局,并且即使您想按维度指定,也不是非常必要,但我建议您使用指定的样式而不是布局。 –