Android通过滑行优化内存

时间:2016-08-18 16:24:45

标签: java android out-of-memory android-glide

我的应用程序中存在很大的内存问题。在我看来,我用Glide动态加载了很多头像。

如何在加载ImageView后释放内存?

for (int i = 0; i < profils.length(); i++, col++) {
if (col == column) {
    col = 0;
    row++;
}
ll = (LinearLayout) View.inflate(context, R.layout.item_community, null);
param = new GridLayout.LayoutParams();
param.height = ((Globals.metrics.widthPixels - column) / column);
param.width = param.height;
param.rightMargin = 5;
param.topMargin = 5;
param.setGravity(Gravity.CENTER);
param.columnSpec = GridLayout.spec(col);
param.rowSpec = GridLayout.spec(row);
profil = (JSONObject) profils.get(i);
avatar = profil.getString("avatar");
final int id_profil = profil.getInt("id");
final ImageView imgProfilAvatar = (ImageView) ll.findViewById(R.id.profilAvatar);
Glide.with(context)
    .load(avatar)
    .crossFade()
    .diskCacheStrategy(DiskCacheStrategy.ALL)
    .into(imgProfilAvatar);

layout.addView(ll, param); }

THX

0 个答案:

没有答案