我有一個字節數組,其中包含從網絡中獲取的圖像。我懶惰地加載他們在我的UI活動(或者我想至少:D)使用Bitmapfactory,BitmapDrawable和setImageDrawable。這裏是我的代碼:setImageBitmap沒有可見的效果
RelativeLayout r =(RelativeLayout) adap.getGroupView(Integer.parseInt(groupPos), false, null, null);
ImageView iv = (ImageView) r.findViewById(R.id.imgGruppo);
Log.w("",""+raw_img.length);
Bitmap bm = BitmapFactory.decodeByteArray(raw_img, 0, raw_img.length);
Drawable drawable = new BitmapDrawable(bm);
Log.i("","pre setimage");
iv.setImageDrawable(drawable);
//added for testing only, with no effects.
//((ELA) Activity_Titoli_2.this.getExpandableListAdapter()).notifyDataSetChanged();
//ELA is my expandable list adapter
Log.i("","post setimage"+bm.getRowBytes()); //just to see that i have actual data in raw_img and such
這裏是XML參與
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayoutTitoli2_gruppo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textNomeGruppo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Large Text"
android:textColor="#FF0000"
android:padding="14dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textNoteGruppo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textNomeGruppo"
android:paddingLeft="14dp"
android:paddingRight="14dp"
android:paddingBottom="7dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageView
android:id="@+id/imgGruppo"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:src="@drawable/icon"
/>
</RelativeLayout>
我已經加入「機器人:SRC ......」只是檢查是否ImageView的是可見的,並且它是。唯一的問題是我無法改變它! 我已經嘗試setImageBitmap,只使用我創建的位圖,我試圖setimageDrawable創建一個BitmapDrawable,但沒有任何影響。沒有錯誤,沒有任何東西。 請問,錯誤在哪裏?謝謝
它是否有助於後iv.setImageDrawable(繪製)來調用iv.invalidate()? –
如果我在代碼中添加invalidate(),那麼也沒什麼變化 –
,這要歸功於那些沒有說出任何建設性內容的人。歡呼聲,男人。 –