菜鸡教程之App

import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.nostra13.universalimageloader.utils.StorageUtils;

import java.io.File;

public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        initImageLoader();


    }

    private void initImageLoader() {
        File cacheDirectory = StorageUtils.getOwnCacheDirectory(getApplicationContext(), "image");
        ImageLoaderConfiguration configuration = new ImageLoaderConfiguration
                .Builder(getApplicationContext())
                .diskCache(new UnlimitedDiskCache(cacheDirectory))
                .diskCacheSize(50 * 1024 * 1024)
                .diskCacheFileCount(1000)
                .defaultDisplayImageOptions(displayOptions())
                .build();
        ImageLoader.getInstance().init(configuration);

    }

    private DisplayImageOptions displayOptions() {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                //图片色彩模式
                .bitmapConfig(Bitmap.Config.RGB_565)
                .displayer(new RoundedBitmapDisplayer(50))
                .cacheOnDisk(true)
                .build();
        return options;
    }

}

 

你可能感兴趣的:(菜鸡教程之App)