软件编程
位置:首页>> 软件编程>> Android编程>> Android实现本地图片选择及预览缩放效果

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

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

标签:Android,图片选择,图片预览

在做项目时经常会遇到选择本地图片的需求,以前都是懒得写直接调用系统方法来选择图片,但是这样并不能实现多选效果,最近又遇到了,所以还是写一个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

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com