Android动态图片选择的一种简单实现方式


layout: post
title: Android动态图片选择的一种简单实现方式
date: 2018-01-20 20:20:08
tags:

  • Android开发
    categories:
  • Android开发

很久没有更新博客了,以后还是决定每个月来更新一遍。本次到来的是一个常用的场景,比如我们在发朋友圈的时候,我们可以选择多张照片,也可以删除之前选择的,但是最多一般会有个上限,达到上限之后一般添加的就消失了。这里给出一个简单的实现思路。

效果图

  • 我们还是先看看效果图
  • 首先是没有图片的时候

image

  • 然后我们选择两张图片

image

  • 选可以点图片右上交的×删除一张

image

  • 最后是选择6张,继续添加标志消失(我这里上限是6张,后面读者可以更新代码自己设置上限)

image

代码实现

  • 这里简单的提供一种实现方式
  • 我这里是利用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"</
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值