今天给大家介绍的是一个相册的开源框架,很强悍,借官网的话说就是:快速,高效,低耗相册选择器,抽取自Telegram,支持单选,多选,预览,缩放,滑动取消预览,QQ选择特性,如果你正要开发相册功能,或者图片查看器等功能,绝对不要错过
项目地址:
https://github.com/TangXiaoLv/TelegramGallery/blob/master/README_CN.md
引入项目(不要太简单)
刚刚更新了AS,发现2.2加了很多功能哦,可以更新用一下。
build.gradle (Modle)
dependencies {
compile 'com.library.tangxiaolv:telegramgallery:1.0.1'
}
AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<activity android:name="com.tangxiaolv.telegramgallery.GalleryActivity" />
然后就可以在项目中使用了:
//打开相册
方式一:
GalleryActivity.openActivity(
Activity activity,
String[] filterMimeTypes,//过滤掉指定类型,遵守MIME Type类型规范。eg:new String[]{"image/gif","image/png"}
boolean singlePhoto,//true 单选,false 多选
int limitPickPhoto,//图片可选数量限制,当singlePhoto=false时生效
int requestCode)//请求码
方式二:
GalleryActivity.openActivity(Activity activity, boolean singlePhoto, int limitPickPhoto,int requestCode)
方式三:
GalleryActivity.openActivity(Activity activity, boolean singlePhoto, int requestCode)
//接受返回值
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//照片路径集合返回值
List<String> photos = (List<String>) data.getSerializableExtra(GalleryActivity.PHOTOS);
//视频路径集合返回值
List<String> vides = (List<String>) data.getSerializableExtra(GalleryActivity.VIDEOS);
}
贴一下我的代码,其实关键就一行,相册功能就完成了:
public class MainActivity extends AppCompatActivity {
public static final int REQUEST_CODE = 0x1;
private Button btnOpen;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
private void init() {
btnOpen = (Button) findViewById(R.id.btnOpen);
btnOpen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
GalleryActivity.openActivity(MainActivity.this, false, 5, REQUEST_CODE);
}
});
}
}
怎么感觉都是官网上copy下来的,但是用起来就是这么简单。好东西学会分享,来一张效果图: