android中的图片选择器,实现微信发布朋友圈多图选择上传功能

本文介绍如何在Android应用中实现类似QQ和微信的多图选择上传功能。通过使用原生的图片选择器框架,如"multiple-images-selector"和"Matisse",详细阐述布局代码、Java功能实现及权限管理。适合初级开发者,提供了相关框架的源码和使用步骤,并展示了运行效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本片文章是根据项目要求的思路去学习其他的博主改良的思路,思路会有雷同,但是该文确实属于本人原文创作,参考链接会在文章最后展示(啊啊啊啊啊,好官方。。。。)

先说一下项目的功能要求,类似于QQ和微信在举报\投诉用户时的界面,需要要求用户上传相关违规的聊天截图,当然在实现这个功能之前用户是已经将截图保存到手机相册里的,所以这个多图上传的功能就比较简单了,当时在做这个功能的时候本人也是从网上查找了很多资料,我一开始的思路是用代码去调系统相册,然后从系统相册去选择图片,但是运行之后发现图片只能选择一张,不能多张选择,这不符合开发逻辑(主要原因还是自己经验不足,竟然不知道还有图片选择器这个框架),发现图片选择器的相关的框架种类还是有多的的,有原生的也有大牛直接用代码手敲出来的,(但是本人更喜欢原生的,因为大牛的思路并不是人人都能理解的。。。。)所以我就不多说大牛的了,我来例举几个原生的,初级码农还是容易理解的哦,不说了,直接来给大家介绍一下吧!

布局代码:只展示显示图片的那部分代码哈

<androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">
           
            <GridView
                android:id="@+id/add_pic"
                android:layout_width="200dp"
                android:layout_height="fill_parent"
                android:layout_marginStart="30dp"
                android:background="@drawable/input_bg"
                android:minHeight="56dp"
                android:scrollbars="none"
                android:layout_margin="10dp"
                android:visibility="gone"
                android:gravity="fill_horizontal"
                android:stretchMode="columnWidth"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintRight_toLeftOf="@id/btn_add_pic"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
//点击该按钮跳转到系统图片选择器中
            <Button
                android:id="@+id/btn_add_pic"
                android:layout_width="56dp"
                android:layout_height="56dp"
                android:layout_margin="10dp"
                android:background="@drawable/add_picture_bg"
                android:foreground="@mipmap/add"
                android:foregroundGravity="center"
                app:backgroundTint="#EFEFEF"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toEndOf="@+id/add_pic"
                app:layout_constraintTop_toTopOf="parent" />
                
        </androidx.constraintlayout.widget.ConstraintLayout>
<
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值