我已成功设置从drawable目录(本地)成功加载图像,我正在考虑更改它,以便它将从Web加载图像。
我在GridView中显示图像,我需要对代码进行哪些操作才能从网上加载它们?
任何帮助都将不胜感激,谢谢。
适配器:
package com.question;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class AdapterViewADV extends BaseAdapter {
private Context mContext;
public Integer[] mThumbIds = {
R.drawable.Image1,
R.drawable.Image2,
R.drawable.Image3,
R.drawable.Image4,
R.drawable.Image5,
R.drawable.Image6
};
public AdapterViewADV(Context c){
mContext = c;
}
@Override
public int getCount() {
return mThumbIds.length;
}
@Override
public Object getItem(int position) {
return mThumbIds[position];
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
imageView.setImageResource(mThumbIds[position]);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(NO_SELECTION, NO_SELECTION));
return imageView;
}
}
答案 0 :(得分:4)
以下是以下示例......
http://www.ethemsulan.com/2011/05/how-to-load-internet-images-in-gridview-android-sample-2.html
https://github.com/desertjim/LazyLoadingGridView
https://github.com/nostra13/Android-Universal-Image-Loader
https://github.com/koush/UrlImageViewHelper
Lazy load of images in ListView
images url are not displaying in grid
试试这些例子,你可以得到一些想法......