设为首页 加入收藏

TOP

xUtils使用详细介绍(三)
2017-10-12 10:03:22 】 浏览:7544
Tags:xUtils 使用 详细 介绍
//自动为文件命名 params.setAutoRename(true); x.http().post(params, new Callback.ProgressCallback<file>() { @Override public void onSuccess(File result) { //apk下载完成后,调用系统的安装方法 Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(result), "application/vnd.android.package-archive"); startActivity(intent); } @Override public void onError(Throwable ex, boolean isOnCallback) { } @Override public void onCancelled(CancelledException cex) { } @Override public void onFinished() { } //网络请求之前回调 @Override public void onWaiting() { } //网络请求开始的时候回调 @Override public void onStarted() { } //下载的时候不断回调的方法 @Override public void onLoading(long total, long current, boolean isDownloading) { //当前进度和文件总大小 Log.i("JAVA","current:"+ current +",total:"+total); } }); ### 六、图片加载模块 xUtils3图片模块,重点在于加载图片的4个bind方法,loadDrawable与loadFIle用法和ImageOptions用法 ### bind的几个方法
void bind(ImageView view, String url);

void bind(ImageView view, String url, ImageOptions options);

void bind(ImageView view, String url, Callback.CommonCallback<Drawable> callback);

void bind(ImageView view, String url, ImageOptions options, Callback.CommonCallback<Drawable> callback);

Callback.Cancelable loadDrawable(String url, ImageOptions options, Callback.CommonCallback<Drawable> callback);

Callback.Cancelable loadFile(String url, ImageOptions options, Callback.CacheCallback<File> callback);
1.首先获取ImageView控件
@ViewInject(R.id.iv1)
ImageView image01;
@ViewInject(R.id.iv2)
ImageView image02;
...
2.定义图片网络地址或本地地址
String[] urls = {
        "http://img4.imgtn.bdimg.com/it/u=3182769660,1810895318&fm=23&gp=0.jpg",
        "http://img2.imgtn.bdimg.com/it/u=1278435851,1308167727&fm=23&gp=0.jpg",
        "https://www.cppentry.com/upload_files/article/98/1_khtxz__.jpg",
        "https://www.cppentry.com/upload_files/article/98/1_h0jds__.jpg"
		...


};	
3,通过ImageOptions.Builder().set方法设置图片的属性 然后通过bind方法加载图片,显示图片方法setImg()如下:
private void setImg() {
    /**
     * 通过ImageOptions.Builder().set方法设置图片的属性
     */
    ImageOptions options = new ImageOptions.Builder().setFadeIn(true).build(); //淡入效果
    //ImageOptions.Builder()的一些其他属性:

    //.setCircular(true) //设置图片显示为圆形
    //.setSquare(true) //设置图片显示为正方形
    //setCrop(true).setSize(200,200) //设置大小
    //.setAnimation(animation) //设置动画
    //.setFailureDrawable(Drawable failureDrawable) //设置加载失败的动画
    //.setFailureDrawableId(int failureDrawable) //以资源id设置加载失败的动画
    //.setLoadingDrawable(Drawable loadingDrawable) //设置加载中的动画
    //.setLoadingDrawableId(int loadingDrawable) //以资源id设置加载中的动画
    //.setIgnoreGif(false) //忽略Gif图片
    //.setParamsBuilder(ParamsBuilder paramsBuilder) //在网络请求中添加一些参数
    //.setRaduis(int raduis) //设置拐角弧度
    //.setUseMemCache(true) //设置使用MemCache,默认true

    /**
     * 加载图片的4个bind方法
     */
    x.image().bind(image01, urls[0]);

    x.image().bind(image02, urls[1], options);

    x.image().bind(image03, urls[2], options, new Callback.CommonCallback<Drawable>() {
        @Override
        public void onSuccess(Drawable result) {
        }
        @Override
        public void onError(Throwable ex, boolean isOnCallback) {
        }
        @Override
        public void onCancelled(CancelledException cex) {
        }
        @Override
        public
首页 上一页 1 2 3 4 5 下一页 尾页 3/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇svn基本常见操作设置 下一篇一步一步实现android studio代码..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目