2010-06-22 69 views
0

我有一個ImageView對象,我設置android:src =「@ drawable/some_xml_file」而不是標準的png,它似乎並不總是呈現drawable,正如你可以看到的在這裏的第一行(它也會間歇性地發生在其他行中):alt text http://www.freeimagehosting.net/uploads/d09b549a9d.jpgAndroid ImageView與繪製不總是呈現

我試過設置src &的背景屬性,但它們都具有相同的效果。從我的列表視圖行項目的源代碼是這樣的:

<ImageView android:id="@id/action_button" android:background="@drawable/action_box" 
    android:layout_width="25dip" android:layout_height="25dip" 
    android:layout_alignParentRight="true" android:layout_marginTop="10dip" /> 

然後我RES /繪製/ action_box.xml是這樣的:

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

    <shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle"> 
     <gradient 

      android:startColor="#81c557" 
      android:endColor="#539942" 
      android:angle="270"/> 
     <stroke android:width="1dip" android:color="#a8d78a" /> 

+0

你重寫,或做任何特殊的ListView適配器的getView方法嗎? – 2010-06-22 22:21:25

+1

你有沒有使用'hierarchyviewer'來確定你的'ImageView'是否丟失,不可見,被拖出屏幕等? – CommonsWare 2010-06-22 22:47:27

+0

是否解決了?你也不需要使用ImageView;你可以使用視圖與android:背景。 – 2010-08-03 02:27:21

回答

0

我沒有解決這個問題,而這個問題與getView()方法中的條件有關。我基本上學會了硬性規定,你應該總是明確地處理所有情況,當你設置可見性/寬度等。

+0

您很快就會了解到,如果您回收視圖,則必須重置*狀態之間可能有所不同的所有*屬性,並且您應該提供一種方法以便您可以從任何一種狀態轉換到另一種狀態,而無需麻煩。 – dcow 2014-03-08 18:39:56