Android实现本地图片选择及预览缩放效果

作者:lylodlig 时间:2023-09-27 14:07:28 

在做项目时经常会遇到选择本地图片的需求,以前都是懒得写直接调用系统方法来选择图片,但是这样并不能实现多选效果,最近又遇到了,所以还是写一个demo好了,以后也方便使用。还是首先来看看效果:

Android实现本地图片选择及预览缩放效果

显示的图片使用RecyclerView实现的,利用Glide来加载;下面弹出的图片文件夹效果是采用PopupWindow实现,这里比采用PopupWindow更方便,弹出显示的左边图片是这个文件夹里的第一张图片;选中的图片可以进行预览,使用网上一个大神写的来实现的;至于图片的获取是用ContentProvider。

看看主界面的布局文件,上面一栏是一个返回按钮和一个跳转预览界面的按钮,根据是否有选中的图片来设置它的点击和显示状态;中间就是一个用于显示图片的RecyclerView,左下角是显示文件夹的名字可点击切换,右下角就是确定按钮。


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.cdxsc.imageselect_y.ImageSelecteActivity">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@android:color/white">

<ImageButton
 android:id="@+id/ib_back"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerVertical="true"
 android:layout_marginLeft="10dp"
 android:background="@mipmap/action_bar_back_normal" />

<TextView
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerVertical="true"
 android:layout_marginLeft="10dp"
 android:layout_toRightOf="@id/ib_back"
 android:text="选择图片"
 android:textColor="#000"
 android:textSize="16sp" />

<TextView
 android:id="@+id/tv_preview"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentRight="true"
 android:layout_centerVertical="true"
 android:layout_marginRight="10dp"
 android:enabled="false"
 android:text="预览"
 android:textColor="#BEBFBF"
 android:textSize="16sp" />
</RelativeLayout>

<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#eeeeee" />

<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"></android.support.v7.widget.RecyclerView>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp">

<TextView
 android:id="@+id/tv_allPic"
 android:layout_width="wrap_content"
 android:layout_height="match_parent"
 android:layout_centerVertical="true"
 android:layout_marginLeft="10dp"
 android:clickable="true"
 android:gravity="center_vertical"
 android:text="所有图片"
 android:textColor="@android:color/black"
 android:textSize="16sp" />

<Button
 android:id="@+id/bt_confirm"
 android:layout_width="wrap_content"
 android:layout_height="35dp"
 android:layout_alignParentRight="true"
 android:layout_centerVertical="true"
 android:layout_marginRight="10dp"
 android:background="@drawable/shape_disable"
 android:enabled="false"
 android:text="确定"
 android:textColor="#676767"
 android:textSize="16sp" />
</RelativeLayout>
</LinearLayout>

来源:http://blog.csdn.net/lylodyf/article/details/54949369

标签:Android,图片选择,图片预览
0
投稿

猜你喜欢

  • Android StickListView实现悬停效果

    2022-06-06 15:54:35
  • IDEA中的.iml文件和.idea文件夹

    2023-11-23 11:47:19
  • 一文搞懂Android RecyclerView点击展开、折叠效果的实现代码

    2023-02-17 14:52:24
  • Retrofit 创建网络请求接口实例过程

    2023-11-23 22:26:43
  • Java人民币小写转大写字符串的实现

    2021-10-24 00:52:34
  • 如何使用MybatisPlus快速进行增删改查详解

    2023-11-03 06:58:13
  • Android中实现EditText密码显示隐藏的方法

    2022-04-13 22:33:56
  • java中 String和StringBuffer的区别实例详解

    2023-06-19 18:48:31
  • Java 网络爬虫基础知识入门解析

    2022-05-16 02:39:06
  • 通过实例学习JAVA对象转成XML输出

    2023-01-14 15:25:35
  • Flutter Shell自动化打包解放双手

    2021-09-17 18:39:15
  • 浅谈Java中Int、Integer、Integer.valueOf()、new Integer()之间的区别

    2023-10-29 20:08:53
  • 配置SpringBoot方便的切换jar和war的方法示例

    2023-11-22 11:57:54
  • c语言颜色代码详解

    2021-05-27 08:07:54
  • 一篇看懂Java中的Unsafe类

    2022-02-13 04:02:38
  • WMI获取硬件信息封装函数方法(联想台式机出厂编号 CPUID BIOS序列号 硬盘信息 显卡信息 MAC地址)

    2023-10-03 13:39:54
  • Springboot整合log4j2日志全解总结

    2021-12-27 22:56:58
  • 高可用架构etcd选主故障主备秒级切换实现

    2022-08-08 23:40:48
  • C#实现导入CSV文件到Excel工作簿的方法

    2022-09-13 12:24:02
  • Android AIDL实现与服务相互调用方式

    2021-08-09 10:57:40
  • asp之家 软件编程 m.aspxhome.com