Android,imageview帮助。如果我替换上一张图片,它是否内存不足?
}Android,imageview帮助。如果我替换上一张图片,它是否内存不足?,android,memory,imageview,Android,Memory,Imageview,} 我在想办法。在我点击按钮后,马被拉布拉多犬取代,我的问题是,马的图片还在记忆中吗?如果我再把它放回去,会不会有两个相同图片的实例 在设置新位图之前,可以尝试检索ImageView内容: public class TestingActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState
我在想办法。在我点击按钮后,马被拉布拉多犬取代,我的问题是,马的图片还在记忆中吗?如果我再把它放回去,会不会有两个相同图片的实例 在设置新位图之前,可以尝试检索ImageView内容:
public class TestingActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getStringIdentifier(getBaseContext(),"main","layout"));
final ImageView iv=(ImageView) findViewById(R.id.imageView1);
final Resources res=getResources();
iv.setImageDrawable(res.getDrawable(R.drawable.horse));
Button b1=(Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
iv.setImageDrawable(res.getDrawable(R.drawable.labrador));
}
});
}
public static int getStringIdentifier(Context context, String name,String resource) {
return context.getResources().getIdentifier(name, resource, context.getPackageName());
}
BitmapDrawable content = (BitmapDrawable)iv.getDrawable();
if (content != null) {
Bitmap contentBitmap = content.getBitmap();
if (contentBitmap != null) {
contentBitmap.recycle();
contentBitmap = null;
}
}