简介
Matisse是知乎开源的图片选择框架:https://github.com/zhihu/Matisse
中文文档:https://blog.csdn.net/qiaoshi96_bk/article/details/76164913
使用:
1. 需要在Glide中实现:
repositories {
jcenter()
}
implementation 'com.zhihu.android:matisse:0.5.3-beta3'
implementation 'com.github.bumptech.glide:glide:4.10.0'
2. 调出图片选择框
Matisse.from(UploadZoneActivity.this) //Activity .choose(MimeType.ofAll()) //选择全部(包括视频) .countable(true) // 有序选择图片 .maxSelectable(9) //最大选择数量为9 .gridExpectedSize(400) //图片显示表格的大小 .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) .thumbnailScale(0.85f) //缩放比率 .theme(R.style.Matisse_Zhihu) //主题 暗色主题 R.style.Matisse_Dracula .imageEngine(new GlideEngine()) //加载方式 .forResult(REQUEST_CODE_CHOOSE); //结果返回码 ,在onActivityResult中获取
3. 获取返回结果(URi)
private ArrayList<Uri> mSelected; @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_CHOOSE && resultCode == RESULT_OK) { mSelected = (ArrayList<Uri>) Matisse.obtainResult(data); Log.d("Matisse", "mSelected: " + mSelected); } }