我有这个XML和代码我添加了来自http://developer.android.com/training/displaying-bitmaps/load-bitmap.html的代码,因为指南说明了如何有效地加载位图但我仍然从logcat中出现内存错误。任何帮助
更新我现在使用的是PICASSO,但仍然没有记忆错误。这是坚果
我有这个代码ALREADY
ImageView targetImage;
ImageView targetImage2;
ImageView targetImage3;
ImageView targetImage4;
ImageView targetImage5;
ImageView targetImage6;
ImageView targetImage7;
ImageView targetImage8;
ImageView targetImage9;
ImageView targetImage10;
ImageView targetImage11;
ImageView targetImage12;
ImageView targetImage13;
ImageView targetImage14;
private Context context;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.app3);
vf = (ViewFlipper) findViewById(R.id.fliping);
targetImage = (ImageView) findViewById(R.id.imageView1);
targetImage2 = (ImageView) findViewById(R.id.imageView2);
targetImage3 = (ImageView) findViewById(R.id.imageView3);
targetImage4 = (ImageView) findViewById(R.id.imageView4);
targetImage5 = (ImageView) findViewById(R.id.imageView5);
targetImage6 = (ImageView) findViewById(R.id.imageView6);
targetImage7 = (ImageView) findViewById(R.id.imageView7);
targetImage8 = (ImageView) findViewById(R.id.imageView8);
targetImage9 = (ImageView) findViewById(R.id.imageView9);
targetImage10 = (ImageView) findViewById(R.id.imageView10);
targetImage11 = (ImageView) findViewById(R.id.imageView11);
targetImage12 = (ImageView) findViewById(R.id.imageView12);
targetImage13 = (ImageView) findViewById(R.id.imageView13);
targetImage14 = (ImageView) findViewById(R.id.imageView14);
Picasso.with(context).load(R.drawable.gr).resize(50, 50).centerCrop().into(targetImage);
Picasso.with(context).load(R.drawable.calvitcdetails).resize(50, 50).centerCrop().into(targetImage2);
Picasso.with(context).load(R.drawable.kapedetails).resize(50, 50).centerCrop().into(targetImage3);
Picasso.with(context).load(R.drawable.glutafitdetails).resize(50, 50).centerCrop().into(targetImage4);
Picasso.with(context).load(R.drawable.pgtdetails).resize(50, 50).centerCrop().into(targetImage5);
Picasso.with(context).load(R.drawable.hilifedetails).resize(50, 50).centerCrop().into(targetImage6);
Picasso.with(context).load(R.drawable.organicbarleyjuicedetails).resize(50, 50).centerCrop().into(targetImage7);
Picasso.with(context).load(R.drawable.barleydetails).resize(50, 50).centerCrop().into(targetImage8);
Picasso.with(context).load(R.drawable.spirulinadetails).resize(50, 50).centerCrop().into(targetImage9);
Picasso.with(context).load(R.drawable.omnisoapdetails).resize(50, 50).centerCrop().into(targetImage10);
Picasso.with(context).load(R.drawable.omnipinkishdetails).resize(50, 50).centerCrop().into(targetImage11);
Picasso.with(context).load(R.drawable.omnidaydetails).resize(50, 50).centerCrop().into(targetImage12);
Picasso.with(context).load(R.drawable.omnitonerdetails).resize(50, 50).centerCrop().into(targetImage13);
Picasso.with(context).load(R.drawable.shuyadetails).resize(50, 50).centerCrop().into(targetImage14);
}
答案 0 :(得分:0)
任何帮助
是的,您可以尝试使用Picasso
加载图片,因为它还可以自动缓存图像和内存管理。我一直认为毕加索的resize()
方法很有帮助。
另外,请考虑使用RelativeLayout
,因为您要嵌套太多LinearLayout
来显示单个ImageView
,这是一个性能杀手。
答案 1 :(得分:0)
关于OutOfMemoryError
的棘手问题在于它们不一定与发生崩溃的代码行有任何关系。如果你的应用程序有内存泄漏,它可能在任何地方。使用最后一位内存的分配可能与泄漏完全无关。您需要学习如何使用Eclipse MAT等内存分析器。