Android——加载图片第三方工具——图片加载中

Android——加载图片第三方工具——图片加载中





package com.example.dell.jreduch07.application;

import android.app.Application;

import com.example.dell.jreduch07.util.FileUitlity;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;

/**
 * Created by dell on 2016/8/26.
 */

/*
在清单文件里的    <application
                    android:name=".application.MyApplication"
                    加上name属性
 */
public class MyApplication extends Application {
    @Override
    //走完这个再去启动Activity
    public void onCreate() {
        super.onCreate();
        //初始化ImagerLoader
        ImageLoaderConfiguration config
                = new ImageLoaderConfiguration.Builder(this)
                .denyCacheImageMultipleSizesInMemory()
                .threadPriority(Thread.NORM_PRIORITY - 2)
                .memoryCacheSize((int) Runtime.getRuntime().maxMemory() / 8)
                .diskCacheSize(50 * 1024 * 1024)
                .diskCacheFileNameGenerator(new Md5FileNameGenerator())
                .discCache(new UnlimitedDiskCache(FileUitlity.getInstance(this, "imagCache").makeDir("imagCache")))
                .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
                .imageDownloader(new BaseImageDownloader(this, 60 * 1000, 60 * 1000))
                .build();
        ImageLoader.getInstance().init(config);
    }
}
package com.example.dell.jreduch07.util;

import android.graphics.Bitmap;
import android.widget.ImageView;
import com.example.dell.jreduch07.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;

public class ImageLoaderUtil {

	private static DisplayImageOptions options =new DisplayImageOptions.Builder()
										.showImageOnLoading(R.drawable.banner_01)
										.showImageOnFail(R.drawable.banner_01)
										.showImageForEmptyUri(R.drawable.banner_01)
										.cacheInMemory(true)
										.cacheOnDisk(true)
										.bitmapConfig(Bitmap.Config.RGB_565)
										.resetViewBeforeLoading(true)
										.imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
										.displayer(new FadeInBitmapDisplayer(200))
										.build();
	private static DisplayImageOptions optionsBig = new DisplayImageOptions.Builder()
			.showImageOnLoading(R.drawable.banner_02)
			.showImageOnFail(R.drawable.banner_02)
			.showImageForEmptyUri(R.drawable.banner_02)
			.cacheInMemory(true).cacheOnDisk(true)
			.bitmapConfig(Bitmap.Config.RGB_565).resetViewBeforeLoading(true)
			.imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
			.displayer(new FadeInBitmapDisplayer(200)).build();
	private static DisplayImageOptions headerOptioins = new DisplayImageOptions.Builder()
			//当图片加载的时候先显示的(暂无图片)
										.showImageOnLoading(R.drawable.default_head)
			//加载失败的时候显示
										.showImageOnFail(R.drawable.default_head)
			//没有图片的时候
										.showImageForEmptyUri(R.drawable.default_head)
			//缓存进内存
										.cacheInMemory(true)
			//缓存进SD卡
										.cacheOnDisk(true)
										.bitmapConfig(Bitmap.Config.RGB_565)
			//在加载图片之前清空imageView
										.resetViewBeforeLoading(true)
			//缩放格式
										.imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
			//显示模式
										.displayer(new FadeInBitmapDisplayer(200))
										.build();

	public static void display(String uri,ImageView imageView){
		//imageView传给...   options格式设置
		ImageLoader.getInstance().displayImage(uri, imageView, options);
	}
	//大图片
	public static void displayBigPhoto(String uri,ImageView imageView){

		ImageLoader.getInstance().displayImage(uri, imageView, optionsBig);
	}
   //加载用户头像图片  小图片
	public static void displayUserHeader( String uri,ImageView imageView){
		ImageLoader.getInstance().displayImage(uri, imageView, headerOptioins);
	}
}

package com.example.dell.jreduch07;


import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;

import com.example.dell.jreduch07.util.ImageLoaderUtil;

public class ImageLoadActivity extends AppCompatActivity {
    private ImageView show;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_load);
        show= (ImageView) findViewById(R.id.show);
        String url="http://img03.sogoucdn.com/app/a/100520024/4ae2d299ac7f183f54bd4b4ccc1f5c7e";
        ImageLoaderUtil.displayBigPhoto(url, show);
    }
}

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.dell.jreduch07.ImageLoadActivity">
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/show"/>
</RelativeLayout>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值