2011-09-19 157 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」 )