// 必须实现AQuery这个类
AQueryaq=newAQuery(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();
@Override
publicViewonCreateView(LayoutInflaterinflater,ViewGroupcontainer,BundlesavedInstanceState){
Viewview=inflater.inflate(getContainerView(),container,false);
aq=newAQuery(getActivity(),view);
returnview;
}
boolean fileCache = true;
aq.id(R.id.image1).image("http://www.vikispot.com/z/images/vikispot/android-w.png", 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 = "http://farm6.static.flickr.com/5035/5802797131_a729dac808_s.jpg";
Bitmap preset = aq.getCachedImage(thumbnail);
// 加载大图片前先显示小图片
String imageUrl = "http://farm6.static.flickr.com/5035/5802797131_a729dac808_b.jpg";
aq.id(R.id.image).image(imageUrl, false, false, 0, 0, preset, AQuery.FADE_IN);
2.6 在加载图片的时候显示进度条,progress里面传入id
String imageUrl = "http://farm6.static.flickr.com/5035/5802797131_a729dac808_b.jpg";
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-Query(AQuery)是一个轻量级的...希望你会导入:1AndroidQuery该工程作为一个库2.AndroidQueryDemo该工程引入AndroidQuery;AndroidQueryTest工程的用法和2一样。GitHub上的一个开源项目该兴趣就研究下吧。
作者bjzhou,源码Coolapk-kotlin,这是一款非常不错的应用商店项目案例,酷安应用商店开源版客户端应用项目源码。点此下载 Demo apk酷市场 V7 版 API 相关所有接口使用统一的前缀: https://api.coolapk.com/v6/...
是 Android 上的一个异步从网络上获取图片并进行浏览的开源组件,可自动在本地进行缓存。该项目是 GreenDroid 的一部分。 13、仿Path按钮动画效果 PathButton 仿照Path应用首页左下角的Button动画效果写了个简单的...
小马快递 前言 这是我第一个独立完成的项目,时隔多年又把它拿出来重构了一下代码。 项目地址:https://github.com/wangchenyan/ponyexpress ...public static void query(String type, String p
在项目的程序目录build.gradle中加入 dependencies { compile 'com.ml.miniorm:miniorm:1.1.8' } 基本方法: 创建表: StuDao stuDao=new StuDao(); stuDao.createTable(); 新增: ...
COCOQuery.zip,将链式编程引入android ui开发android库androidquery的启发,将链式ui编程api引入ui开发,旨在简化android ui开发。
本项目旨在演示Android Architecture Component的Room Persistence Library的使用; 在 Google I/O 2017 上宣布。 Room 是一个基于注释的 SQL 数据库库。 它使您可以相当轻松地: 创建一个可用的 SQL 数据库 创建...
query and so on. Keywords: Activity Management, Face Recognition 1. 简介(Introduction) 1.1 背景(Background) 该项目是本人的本科毕业设计作品,由本人负责全栈开发(),同时也旨在通过该项目熟悉多个 ...
适用于Android的MonoTouch和Mono! GPLv3许可证用于公共领域。 如果您打算在CLOSED SOURCE项目中使用它,请与我联系-andres.vogler@gmail.com! 可以直接使用XMLRPC或使用随附的代理进行通信:* .net远程处理用于从...
一个简单的基于Android的Sqlite数据库的操作封装,它有如下的好处:便捷地创建表和增添表字段灵活的数据类型处理通过操作对象来insert或者update表记录支持多种查询方式,支持多表自定义的复杂查询,支持分页查询支持...
app:bubbleTab_image4="@drawable/ic_query" /> <android.support.v4.view.ViewPager android:id="@ id/viewPager" android:layout_width="match_parent" android:layout_height="match_parent"/>...
SquiDB 是 Android 平台下 SQLite 数据库的封装层。简化了 SQlite 数据库的操作,合并了类型安全对象和面向对象 SQL 语句处理。示例代码:long ageCutoff = System.currentTimeMillis() - (DateUtil.YEAR_IN_...
当做一款APP,需要选择本地图片时,首先考虑的无疑是系统相册,但是Android手机五花八门,再者手机像素的提升,大图无法返回等异常因数,导致适配机型比较困难,微信、QQ都相继的在自己的APP里集成了图片选择功能,...
ANGROM 是一个简单的android 数据库 dsl, 解决了数据库版本控制问题, 提供了select查询类. 使用入门 下载并导入jar包 创建MyApplication类 public class MyApplication extends...