【发布时间】:2017-07-24 13:07:50
【问题描述】:
我有一个字节数组,其中包含从网上获取的图像。我正在使用 Bitmapfactory、BitmapDrawable 和 setImageDrawable 将它们懒惰地加载到我的 UI 活动中(或者我正在尝试至少:D)。这是我的代码:
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>
我添加了“android:src...”只是为了检查 imageview 是否可见,并且确实如此。唯一的问题是我无法改变它! 我试过 setImageBitmap,只使用我创建的位图,我尝试 setimageDrawable 创建一个 BitmapDrawable,但根本没有效果。没有错误,没有什么。 请问,错在哪里?谢谢
【问题讨论】:
-
在 iv.setImageDrawable(drawable) 之后调用 iv.invalidate() 有帮助吗?
-
如果我将 invalidate() 添加到代码中,没有任何变化
-
另外,感谢那个在没有说任何建设性的情况下投反对票的人。干杯,伙计。
-
我也遇到了同样的问题,你有没有发现是什么原因造成的?
-
不,抱歉。它发生在很多年前,在一个较旧的 android 版本中,我根本不记得了。即使我记得,我想它也不会再适用了。