layout: post
title: Android动态图片选择的一种简单实现方式
date: 2018-01-20 20:20:08
tags:
- Android开发
categories: - Android开发
很久没有更新博客了,以后还是决定每个月来更新一遍。本次到来的是一个常用的场景,比如我们在发朋友圈的时候,我们可以选择多张照片,也可以删除之前选择的,但是最多一般会有个上限,达到上限之后一般添加的就消失了。这里给出一个简单的实现思路。
效果图
- 我们还是先看看效果图
- 首先是没有图片的时候
- 然后我们选择两张图片
- 选可以点图片右上交的×删除一张
- 最后是选择6张,继续添加标志消失(我这里上限是6张,后面读者可以更新代码自己设置上限)
代码实现
- 这里简单的提供一种实现方式
- 我这里是利用RecyclerView来实现,接下来具体看下
- 首先是主布局文件,其实就是一个RecyclerView
<android.support.v7.widget.RecyclerView
android:id="@+id/rl_repair"
android:layout_width="match_parent"
android:layout_height="250dp">
</android.support.v7.widget.RecyclerView>
- 然后主要逻辑代码在adapter,我们先看看adapter的布局
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="10dp">
<ImageView
android:id="@+id/iv_add"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@mipmap/bg_scan"/>
<ImageView
android:id="@+id/iv_photo"</