2011-09-19 96 views
7

我有一个相当简单的xml文件,它有一个图像按钮。该图像在图形布局xml设计器上显示得很好,运行开发版本时显示正常,但只要创建签名的apk文件并运行它,图像就不再显示。这只是一个空的按钮。我想不出为什么,有什么想法?该XML文件是这样的:Android:Drawable not showing up

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/navigation_root" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" > 

<TextView 
    android:id="@+id/navigation_text" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="5dp" 
    android:text="TextView" 
    android:textAppearance="?android:attr/textAppearanceLarge" > 
</TextView> 

<SeekBar 
    android:id="@+id/navigation_seekbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_vertical" 
    android:layout_weight="1" 
    android:padding="5dp" > 
</SeekBar> 

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="5dp" > 

    <ImageButton 
     android:id="@+id/part_select_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/chapter_select" > 
    </ImageButton> 

    <Button 
     android:id="@+id/navigation_ok_button" 
     android:layout_width="75dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:text="@string/ok" > 
    </Button> 

    <Button 
     android:id="@+id/navigation_cancel_button" 
     android:layout_width="75dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:text="@string/cancel" > 
    </Button> 
</LinearLayout> 

图像0​​是一个相当小的(41 * 41),png文件是在res /绘制的文件夹。

回答

2

尝试把图像中绘制,华电国际和绘制,MDPI文件夹 取决于你使用的设备上运行的应用程序,你的图像中搜索这些文件夹中的...

但在绘制手段puting,图像应该可以在任何地方使用,但是有时候(取决于你的清单设置),这不可能是真的,我的意思是你可以打开兼容模式。

,你也可以在运行时尝试dinamically将图像设置为视图

iv.setImageResource(R.drawable.somethig); 
+0

我不想将它放在特定的屏幕密度文件夹中,因为我希望所有设备都能够在不复印的情况下使用图像。动态设置图像不会改变任何内容,它仍然不会在签名构建中显示出来。谢谢你尝试Luk。 – odiggity

2

有相同的问题,并通过删除所有特殊字符解决它。在我的情况下,它是破折号' - '在文件名中:

background-720.png => background.png

0

我的情况很奇怪。在将FireBase Crash报告集成到我的应用程序之前,一切都是正确的。

我只是说编译'com.google.firebase:firebase-crash:11.0.1' & DrawableLeft消失。当我通过XML去,发现一个警示(在下面衬)。

因此增加了android:drawableStart &问题消失了。

我仍想知道火力碰撞到同一个报告关系。

使用左/右,而不是开始/结束属性中使用重力#LEFT 和重力#权当是布局 语言区域的文字自右向左流渲染可能会出现问题。使用重力#开始和 重力#结束。

同样,在XML重力和layout_gravity属性中,使用开始 而不是左侧。对于诸如paddingLeft和 layout_marginLeft的XML属性,请使用paddingStart和layout_marginStart。

注意:如果您的minSdkVersion小于17,则应添加 旧的左/右属性以及新的开始/右属性。 在旧平台,其中RTL不支持和启动/右 属性是未知的,因此被忽略,你需要旧 左/右属性。

有一个单独的棉绒支票捕捉任何类型的错误。 (注意:对于Gravity#LEFT和Gravity#START,即使针对较老的平台,也可以使用这些常量 ,因为起始位掩码是左位掩码的 的超集,因此您可以使用gravity =“start” )