android query框架demo,Android之使用Android-query框架开发实战(一)

开发android使用android-query框架能够快速的,比传统开发android所要编写的代码要少得很多,容易阅读等优势。

下载文档及其例子和包的地址:

以下内容是我学习的一些心得分享:

第一节:

// 必须实现aquery这个类

aquery aq = new aquery(view);

// 按顺序分析:取得xml对应控件id,设置图片,设置可以显示,点击事件(方法somemethod必须是public修饰)

aq.id(r.id.icon).image(r.drawable.icon).visible().clicked(this, "somemethod");

// 设置文字内容

aq.id(r.id.name).text(content.getpname());

aq.id(r.id.time).text(formatutility.relativetime(system.currenttimemillis(), content.getcreate())).visible();

aq.id(r.id.desc).text(content.getdesc()).visible();

aquery也支持fragment:

@override

public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {

view view = inflater.inflate(getcontainerview(), container, false);

aq = new aquery(getactivity(), view);

return view;

}

第二节: 使用aquery异步加载图片

2.1 从网上读取图片

aq.id(r.id.image1).image(“图片url”);

2.2 缓存控制:  图片过大的话,避免记忆缓存

boolean memcache = false;

boolean filecache = true;

aq.id(r.id.image1).image("", memcache, filecache);

2.3 当下载太多图片的时候需要降低图片采样率,第四个参数为了保证图片质量,一般范围时200-399

aq.id(r.id.image1).image(imageurl, true, true, 200, 0);

2.4 如果下载图片失败,处理的方法:1. 设置一个预定的图片  2. 使imageview不可见或者是gone

aq.id(r.id.image1).image(imageurl, true, true, 0, r.drawable.default_image);

aq.id(r.id.image1).image(imageurl, true, true, 0, aquery.invisible);

aq.id(r.id.image1).image(imageurl, true, true, 0, aquery.gone);

2.5 图片预加载

// 从之前的url取得小图片

string thumbnail = "";

bitmap preset = aq.getcachedimage(thumbnail);

// 加载大图片前先显示小图片

string imageurl = "";

aq.id(r.id.image).image(imageurl, false, false, 0, 0, preset, aquery.fade_in);

2.6 在加载图片的时候显示进度条,progress里面传入id

string imageurl = "";

aq.id(r.id.image).progress(r.id.progress).image(imageurl, false, false);

2.7 图片圆角显示,不支持大图片

imageoptions options = new imageoptions();

options.round = 15;

aq.id(r.id.image).image(url, options);

2.8 图片长宽比例

// 保留原图片比例

aq.id(r.id.image).image(imageurl, true, true, 0, 0, null, aquery.fade_in, aquery.ratio_preserve);

// 自定义图片比例

//1:1, a square

aq.id(r.id.image2).image(imageurl, true, true, 0, 0, null, 0, 1.0f / 1.0f);

aq.id(r.id.image3).image(imageurl, true, true, 0, 0, null, 0, 1.5f / 1.0f);

//16:9, a video thumbnail

aq.id(r.id.image4).image(imageurl, true, true, 0, 0, null, 0, 9.0f / 16.0f);

aq.id(r.id.image5).image(imageurl, true, true, 0, 0, null, 0, 3.0f / 4.0f);

2.9 图片描点,如果图片过高,描点可用来描述图片的哪一部分用于显示

anchor values:

1.0 : display top of the image

0 : display the center of the image

-1.0 : display bottom of the image

aquery.anchor_dynamic : display image with a top bias for photos.

=======================================================

imageoptions options = new imageoptions();

options.ratio = 1;

options.anchor = 1.0;

aq.id(r.id.image1).image(imageurl, options);

2.10 自定义图片加载后的处理

aq.id(r.id.image1).image(imageurl, true, true, 0, 0, new bitmapajaxcallback(){});

2.11 异步从文件加载图片,建议使用降低采样率避免oom

file file = new file(path);

//load image from file, down sample to target width of 300 pixels

aq.id(r.id.avatar).image(file, 300);

//load image from file with callback

aq.id(r.id.avatar).image(file, false, 300, new bitmapajaxcallback(){

@override

public void callback(string url, imageview iv, bitmap bm, ajaxstatus status){

iv.setimagebitmap(bm);

}

});

2.12 如果之前image("url")已经成功,之后的都可以直接使用而不需要重新访问网络,也就是说之后可以离线访问此图像资源

2.13 文件中获取缓冲图片

file file = aq.getcachedfile(url);

2.14 除了imageview,webview也可以用来放图片

aq.id(r.id.web).progress(r.id.progress).webimage(url);

2.15 延迟图片加载,帮助你是否加载正在快速滚动的listview,详情参考文档使用

2.16 图片不使用缓存

aq.id(r.id.image).image(url, false, false);

2.17 缓存配置,缓存一般是保存在内部文件系统,但也可以保存在sdcard里面

file ext = environment.getexternalstoragedirectory();

file cachedir = new file(ext, "myapp");

aqutility.setcachedir(cachedir);

2.18 共享图片,为了与其他程序共享图片,你需要把文件放在sdcard,makesharedfile方法创建缓存地址的一个副本

file file = aq.makesharedfile(url, "android.png");

if(file != null){

intent intent = new intent(intent.action_send);

intent.settype("image/jpeg");

intent.putextra(intent.extra_stream, uri.fromfile(file));

startactivityforresult(intent.createchooser(intent, "share via:"), send_request);

}

2.19 配置,最好把配置写在application的oncreate方法,详细参考文档

2.20 程序退出时候需要把缓存清除

if(istaskroot()){

aqutility.cleancacheasync(this);

}

或者:

if(istaskroot()){

//clean the file cache with advance option

long triggersize = 3000000; //大于3m时候开始清除

long targetsize = 2000000; //直到少于2m

aqutility.cleancacheasync(this, triggersize, targetsize);

}

2.21 低内存处理

public class mainapplication extends application{

@override

public void onlowmemory(){

//clear all memory cached images when system is in low memory

//note that you can configure the max image cache count, see configuration

bitmapajaxcallback.clearcache();

}

}

以上内容就是小编跟大家介绍的android之使用android-query框架开发实战(一),希望大家喜欢,下篇文章跟大家介绍android之使用android-query框架开发实战(二),感兴趣的朋友请持续关注本站。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值