代码之家  ›  专栏  ›  技术社区  ›  jbiral

ImageView PNG被Galaxy S5棒棒糖上的默认Android图标替换

  •  0
  • jbiral  · 技术社区  · 10 年前

    我有一个非常简单的活动显示图像:

    <RelativeLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="wrap_content" >
    
       <ImageView
          android:id="@+id/my_image"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:src="@drawable/activation_background" />
    
    </RelativeLayout>
    

    my_image.png 仅在中 /res/drawable-xhdpi/ 它对我迄今为止尝试过的所有手机都很好,除了带有棒棒糖的Galaxy S5(它在4.4上运行)。在这个特定的手机和版本上 ImageView 而是显示了一种默认的Android图标,它甚至不在我的项目中。

    要修复它,我需要 my_image.png 在里面 /res/drawable-xxhdpi/ 。但我不理解这种行为。它在Nexus 6上运行良好,无需这样做。这是S5 5.0版本的已知问题吗?是否有其他方法可以做到这一点,而不是将图像移动到 drawable-xxhdpi ?

    3 回复  |  直到 10 年前
        1
  •  2
  •   math-eww    10 年前

    嗯,你应该为每种尺寸的屏幕创建可绘制的图形。Android Studio有一个工具可以为您完成此操作-右键单击drawbable并选择new->图像资产

    否则,在棒棒糖和更高版本中,我相信矢量图形是受支持的-请检查此处: https://developer.android.com/training/material/drawables.html

        2
  •  1
  •   Andrea Thacker    10 年前

    如果你能够提供xxhdpi分辨率的图像,你肯定应该添加它。最好的做法是在mdpi、hdpi、xhdpi和xxhdpi文件夹中定义所有图形。

    否则,解决方法是在xhdpi文件夹中创建图像的副本,并将其添加到xxhdpi文件夹。这样一来,xxhdpi的手机仍然有一个可提取的资源可以加载。

        3
  •  0
  •   jbiral    10 年前

    我的问题的解决方法有点奇怪。我简单地重命名了drawbable activation_bg something_activation_bg 。请注意,除了 激活_ bg 正在工作,除了 activation_background 这导致了同样的问题。

    我不知道为什么这是Galaxy S5棒棒糖版本的一个问题。与应用程序外部的任何东西都不应该有任何冲突,所以这真的很奇怪。