我正在尝试创建一个包含不同类别的应用程序,并且每个类别都包含一系列图像(所有图像都是从它们的链接下载的)并且我使用Glide Library ,我做了所有这些,但是内存 ram 有问题我的应用程序需要很多时间内存(值因设备而异)的原因是当我在类别之间移动图像被加载并存储在缓存中,我该如何解决这个问题
这是一个片段.java
public class Art extends Fragment {
GridView myGrid;
CategoryAdapter adapter;
public Art() {
// Required empty public constructor
}
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
final ArrayList<String> movieList = new ArrayList<>();
/*Source Art*/
movieList.add("http://i.imgur.com/INlyb2w.jpg");
movieList.add("http://i.imgur.com/ZvvBaq8.jpg");
/*****/
View v = inflater.inflate(R.layout.fragment_art, container, false);
myGrid= (GridView) v.findViewById(R.id.gridViewCategory);
adapter =new CategoryAdapter(getActivity(),movieList);
myGrid.setAdapter(adapter);
myGrid.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent popup = new Intent(getActivity(), Pop.class);
popup.putExtra("WallpaperURL", movieList.get(position));
startActivity(popup);
}
});
return v;
}
}
class CategoryAdapter extends BaseAdapter {
private Context context;
private ArrayList<String> imageId= new ArrayList<>();
CategoryAdapter(Context context,ArrayList<String> imageId){
this.context=context;
this.imageId=imageId;
}
@Override
public int getCount() {
return imageId.size();
}
@Override
public Object getItem(int position) {
return imageId.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
private class ViewHolder{
ImageView CategoryImage;
ViewHolder(View view){
CategoryImage = (ImageView) view.findViewById(R.id.cat_imageView);
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row=convertView;
ViewHolder holder;
if(row == null){
LayoutInflater inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row=inflater.inflate(R.layout.picture_item,parent,false);
holder=new ViewHolder(row);
row.setTag(holder);
}
else{
holder=(ViewHolder) row.getTag();
}
Glide.with(context).load(imageId.get(position)).placeholder(R.drawable.arrw).into(holder.CategoryImage);
return row;
}
}