使用Android-Universal-Image-Loader加载图片
来源:互联网 发布:java中print是什么意思 编辑:程序博客网 时间:2024/05/09 13:22
gihub地址:https://github.com/nostra13/Android-Universal-Image-Loader
clone地址:https://github.com/nostra13/Android-Universal-Image-Loader.git
在使用这个开源框架时,容易出错的地方是ImageLoader的实例化,因为在源码的例子中,关于ImageLoader的实例化是放在应用程序的Application配置中,在应用加载之前实现的。
当然这样的方法我们可以借鉴:
第一种实例化的办法:
<span style="font-size:18px;">/******************************************************************************* * Copyright 2011-2013 Sergey Tarasevich * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/package com.nostra13.universalimageloader.sample;import android.annotation.TargetApi;import android.app.Application;import android.content.Context;import android.os.Build;import android.os.StrictMode;import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;import com.nostra13.universalimageloader.core.ImageLoader;import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;import com.nostra13.universalimageloader.core.assist.QueueProcessingType;/** * @author Sergey Tarasevich (nostra13[at]gmail[dot]com) */public class UILApplication extends Application {@TargetApi(Build.VERSION_CODES.GINGERBREAD)@SuppressWarnings("unused")@Overridepublic void onCreate() {if (Constants.Config.DEVELOPER_MODE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyDialog().build());StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyDeath().build());}super.onCreate();initImageLoader(getApplicationContext());}public static void initImageLoader(Context context) {// This configuration tuning is custom. You can tune every option, you may tune some of them,// or you can create default configuration by// ImageLoaderConfiguration.createDefault(this);// method.ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).threadPriority(Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory().diskCacheFileNameGenerator(new Md5FileNameGenerator()).diskCacheSize(50 * 1024 * 1024) // 50 Mb.tasksProcessingOrder(QueueProcessingType.LIFO).writeDebugLogs() // Remove for release app.build();// Initialize ImageLoader with configuration.ImageLoader.getInstance().init(config);}}</span>
然后在AndroidManifest.xml中注册,红色标出的地方:
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.nostra13.universalimageloader.sample" android:versionCode="39" android:versionName="1.9.4" > <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="20" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application <span style="color:#FF0000;">android:name=".UILApplication"</span> android:icon="@drawable/ic_launcher" android:label="@string/app_name"android:allowBackup="false"> <activity android:name=".activity.HomeActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".activity.SimpleImageActivity" android:label="@string/ac_name_image_list" /><activityandroid:name=".activity.ComplexImageActivity"android:label="@string/ac_name_complex" /> <!-- Widget --> <receiver android:name=".widget.UILWidgetProvider" > <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_provider" /> <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> </receiver> </application></manifest></span>第二种实例化的办法:
在构造函数中进行实例化:
<span style="font-size:18px;">ImageLoaderConfiguration config = newImageLoaderConfiguration.Builder(context).build();ImageLoader.getInstance().init(config);mImageLoader = ImageLoader.getInstance();</span>注意mImageLoader提前声明。
接下来使用它来加载图片就在github的例子中给出了。
///////////////////////////////////////////////////////////////////////////////学习的教程
http://www.cnblogs.com/kissazi2/p/3886563.html
0 0
- 使用Android-Universal-Image-Loader加载图片
- Android图片异步加载之Android-Universal-Image-Loader使用
- Android图片异步加载之Android-Universal-Image-Loader使用
- 异步加载图片框架Android-Universal-Image-Loader的使用
- Android-Universal-Image-Loader图片加载框架使用
- 使用Android-Universal-Image-Loader加载网络图片
- 图片加载框架Android-Universal-Image-Loader使用及解析
- Android-Universal-Image-Loader图片加载框架使用
- Android-Universal-Image-Loader 异步加载图片
- Android-Universal-Image-Loader加载图片
- Android-Universal-Image-Loader 图片加载库
- 使用Universal-Image-Loader加载图片
- 使用Universal-Image-Loader框架加载图片
- Android加载图片 Universal-Image-Loader图片缓存问题
- Android图片异步加载之Android-Universal-Image-Loader
- Android图片异步加载之Android-Universal-Image-Loader
- Android图片异步加载之Android-Universal-Image-Loader
- Android图片异步加载之Android-Universal-Image-Loader
- 干活快回家看了就哭了
- php 截取utf8 无乱码
- MFC之Hello World
- Gson解析和封装
- MinGw与Cygwin的区别
- 使用Android-Universal-Image-Loader加载图片
- [NIOS II] 串口通信
- 矩阵链乘法
- 房管局和改扩建电饭锅电饭锅
- java版的单向链表的逆序输出
- 水电费根据规划将黄金圣斗士
- 谁看得见风科技阿斯顿
- 房管局和健康就好看了
- 第十一周项目6(2)判断是不是回文数