我需要有效地從服務器和緩存下載圖像,並且需要以網格視圖顯示。我不想使用任何庫。Android延遲加載帶有網格視圖的圖像(不使用任何庫)
任何人都可以幫助我。我對android很陌生。
由於提前, 迪帕克
我需要有效地從服務器和緩存下載圖像,並且需要以網格視圖顯示。我不想使用任何庫。Android延遲加載帶有網格視圖的圖像(不使用任何庫)
任何人都可以幫助我。我對android很陌生。
由於提前, 迪帕克
使用此項目,並添加四個文件到您的項目即https://github.com/thest1/LazyList/tree/master/src/com/fedorvlasov/lazylist
你不需要任何庫。它將獨立工作。
public class LazyAdapter extends BaseAdapter {
private Activity activity;
private String[] data;
private static LayoutInflater inflater=null;
**public ImageLoader imageLoader;**
public LazyAdapter(Activity a, String[] d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
**imageLoader=new ImageLoader(activity.getApplicationContext());**
}
public int getCount() {
return data.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.item, null);
TextView text=(TextView)vi.findViewById(R.id.text);;
ImageView image=(ImageView)vi.findViewById(R.id.image);
text.setText("item "+position);
**imageLoader.DisplayImage(data[position], image);**
return vi;
}
}
檢查粗體字符串。其中自定義LazyAdapter顯示在適配器內設置圖像。該適配器設置爲Gridview。
這一個我已經。但我不知道如何管理網格視圖。你可以給我發一點我想在'公共視圖getView(int位置,查看convertView,ViewGroup父)'內使用的代碼嗎? – Deepak
檢查getview部分,你有ImageLoader類的實例和方法'imageLoader.DisplayImage(data [position],image)' – user1621629
嗨,謝謝:)工作:) – Deepak
爲什麼你不想使用任何庫?我建議Picasso加載一個緩存的圖片和一個自BaseAdapter擴展的自定義適配器。 – msal
下載:http://stackoverflow.com/questions/15549421/how-to-download-and-save-an-image-in-android 顯示和緩存:http://developer.android.com/training/displaying -bitmaps/index.html 爲什麼沒有圖書館?在OutOfMemoryExpedia中運行位圖並不是初學者最容易的任務。 – Apfelsaft
也universal-image-loader https://github.com/nostra13/Android-Universal-Image-Loader是最好的 –