本文实例为大家分享了Android实现图片选择器功能的具体代码,供大家参考,具体内容如下
图片选择功能用的是GitHub上的依赖库、网址
先来看下我运行的效果图如下所示:
,
该依赖库是Android平台上拍照/录像,图片/视频选择,编辑和压缩的一站式解决方案。
添加依赖,在应用程序→build.gradle里面添加依赖
//图片/视频选择,预览,编辑与拍的照 实现“com.github.guoxiaoxing:凤凰:1.0.15”
初始化:
公共类的应用程序扩展应用程序{ @Override 公共空间> 私人空间callUpSelecter(布尔isCamera int类型,int REQUEST_CODE) { 如果(TextUtils.isEmpty(文件标识)){ Phoenix.with () .theme (PhoenixOption.THEME_RED)//主题 .fileType (MimeType.ofImage())//显示的文件类型图片,视频,图片和视频 .maxPickNumber(9)//最大选择数量 .minPickNumber(0)//最小选择数量 .spanCount(4)//每行显示个数 .enablePreview(真正的)//是否开启预览 .enableCamera (isCamera)//是否开启拍的照 .enableAnimation (false)//选择界面图片点击效果 .enableCompress(真正的)//是否开启压缩 .compressPictureFilterSize(300)//多少kb以下的图片不压缩 .compressVideoFilterSize(2018)//多少kb以下的视频不压缩 .thumbnailHeight(160)//选择界面图片高度 .thumbnailWidth(160)//选择界面图片宽度 .enableClickSound (false)//是否开启点击声音 .pickedMediaList (add_lists)//已选图片数据 .videoFilterTime(0)//显示多少秒以内的视频 .mediaFilterSize(0)//显示多少kb以下的图片/视频,默认为0,表示不限制 .start (UploadMorePicActivity。类型,REQUEST_CODE); } }
获取结果:
@Override 保护voidbrush: java; ">/* * * recyclerView适配器基类 */公共抽象类BaseRecyclerAdapter扩展RecyclerView.Adapter { 公共>/* * *由YuShuangPing> & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt; LinearLayout xmlns: android=" http://schemas.android.com/apk/res/android " xmlns:应用=" http://schemas.android.com/apk/res-auto " android: layout_width=" match_parent " android: layout_height=" wrap_content " 面向android:="水平"比; & lt; com.sinosig.ygqd.widget.CustomHeightImageView android: id=癅 + id/iv_pic” android: layout_width=" 230 px " android: layout_height=" 230 px " android: layout_marginBottom=" 28.8 px” 应用:=" 1 "/规模比; & lt;/LinearLayout>
中活动的代码:
公共类UploadMorePicActivity AppCompatActivity延伸 { 私人RecyclerView rl_pic; 私人UpLoadMorePicAdapter适配器; 私人List,add_lists=new ArrayList<的在(); @Override 保护voidbrush: java; "> 公共类CustomHeightImageView android.support.v7.widget延伸。AppCompatImageView { 浮动比例=0; 公共CustomHeightImageView(上下文语境){ 超级(上下文); } 公共CustomHeightImageView(上下文语境,浮动范围){ 超级(上下文); 这一点。规模=规模; } 公共CustomHeightImageView(上下文语境,AttributeSet attrs) { 超级(上下文,attrs); TypedArray a=getContext ()。obtainStyledAttributes (attrs R.styleable.CustomHeightRelativeLayout);=a.getFloat (R.styleable规模。CustomHeightRelativeLayout_scale 1 f);//规模=浮动。 } @Override 保护无效onMeasure (int widthMeasureSpec int heightMeasureSpec) { 如果(规模==1){ 超级。onMeasure (widthMeasureSpec heightMeasureSpec); 其他}{ 超级。onMeasure (widthMeasureSpec MeasureSpec.makeMeasureSpec ( (int) (MeasureSpec.getSize (widthMeasureSpec) *(规模)), MeasureSpec.getMode (widthMeasureSpec))); } } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。