先上图

点击+号就去选择图片

实际上这个添加本身就是一个ListView或者 RecyclerView

只是布局有些特殊

item

<?xml version="1.0" encoding="utf-8"?>
<liu.myrecyleviewchoosephoto.view.SquareRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"> <RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:layout_marginTop="14dp"
android:background="@drawable/shape_white_bg_corner"
> <ImageView
android:id="@+id/ivDisPlayItemPhoto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@null"
android:scaleType="centerCrop"
android:layout_centerInParent="true"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
/> <ImageView
android:id="@+id/ivAddPhoto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="@color/white"
android:scaleType="centerCrop"
android:src="@mipmap/add_photo_refund"
android:visibility="visible"/> <ImageView
android:id="@+id/ivUploadingBg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/shape_grey_bg_corner"
android:visibility="gone"/> <ImageView
android:id="@+id/ivError"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@mipmap/icon_prompt"
android:visibility="gone"/> <TextView
android:id="@+id/tvProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="0%"
android:textColor="@color/white"
android:textSize="16sp"
android:visibility="gone"/> </RelativeLayout> <ImageView
android:id="@+id/ivDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@mipmap/delete_photo"
android:visibility="gone"/> </liu.myrecyleviewchoosephoto.view.SquareRelativeLayout>

在Adpater中判断一个数据是不是为0和是不是最后一个添加的图片就可以了。

 @Override
public int getItemCount() {
if (mDatas == null || mDatas.size() == 0) {
return 1;
} else if (mDatas.size() < mMaxNum) {
return mDatas.size() + 1;
} else {
return mDatas.size();
}
}

这里用到了一个正方形的,容器

package liu.myrecyleviewchoosephoto.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout; /**
* 正方形的RelativeLayout
* Created by 刘楠 on 2016/8/13 0013.16:07
*/
public class SquareRelativeLayout extends RelativeLayout {
public SquareRelativeLayout(Context context) {
super(context);
} public SquareRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
} public SquareRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
} @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { //设置自己测量结果
setMeasuredDimension(getDefaultSize(0,widthMeasureSpec),getDefaultSize(0,heightMeasureSpec)); /**
* 测量子View的
*/
int childWidthSize=getMeasuredWidth();
//高度与宽度一样
widthMeasureSpec =MeasureSpec.makeMeasureSpec(childWidthSize,MeasureSpec.EXACTLY);
heightMeasureSpec =widthMeasureSpec; super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}

这里没有写图片选择器
有兴趣可以看这里

图片选择器:

https://github.com/ln0491/PhotoView

源码:

https://github.com/ln0491/MyRecyleViewChoosePhoto

Android添加图片到ListView或者 RecyclerView显示的更多相关文章

  1. android中ScrollView嵌套ListView或GridView显示位置问题

    Android中ScrollView中嵌套ListView或GridView时在开始进入界面时总是显示中间位置,开头的位置显示不出来.这种情况下只需要在ScrollView的父控件中添加以下两行代码即 ...

  2. Android学习笔记:ListView简单应用--显示文字列表

    在activity中的编写如下代码: final List<String> items = new ArrayList<String>(); //设置要显示的数据,这里因为是例 ...

  3. Android 解决ScrollView嵌入ListView | GridView | ScrollView显示问题

    一.ScrollView中嵌套ListView ScrollView和ListView都是滚动结构,很明显如果在ScrollView中加入ListView,可以预见性的知道,肯定会有显示/滚动的问题, ...

  4. Android开发之漫漫长途 XVI——ListView与RecyclerView项目实战

    该文章是一个系列文章,是本人在Android开发的漫漫长途上的一点感想和记录,我会尽量按照先易后难的顺序进行编写该系列.该系列引用了<Android开发艺术探索>以及<深入理解And ...

  5. android listview 替代品recyclerview详解

    安卓v7支持包下的ListView替代品————RecyclerView   RecyclerView这个控件也出来很久了,相信大家也学习的差不多了,如果还没学习的,或许我可以带领大家体验一把这个艺术 ...

  6. 【腾讯Bugly干货分享】Android ListView与RecyclerView对比浅析--缓存机制

    本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/5811d3e3ab10c62013697408 作者:黄宁源 一,背景 Recy ...

  7. Android ListView item项 显示动画

    (1)使用LayoutAnimation 所谓的布局动画,其实就是为ViewGroup添加显示动画效果,主要用过LayoutAnimationController来控制实现.LayoutAnimati ...

  8. android 项目学习随笔十七(ListView、GridView显示组图)

    ListView.GridView显示组图,处理机制相同 <?xml version="1.0" encoding="utf-8"?> <Li ...

  9. Android根据Button状态(normal,focused,pressed)显示不同背景图片

    Android根据Button状态(normal,focused,pressed)显示不同背景图片 Android中Button 有focused, selected, pressed 等不同状态,通 ...

随机推荐

  1. Util应用程序框架公共操作类(六):验证扩展

    前面介绍了仓储的基本操作,下面准备开始扩展查询,在扩展查询之前,首先要增加两个公共操作类,一个是经常要用到的验证方法,另一个是Lambda表达式的操作类. 很多时候,我们会判断一个对象是否为null, ...

  2. 小菜学习设计模式(一)—模板方法(Template)模式

    前言 设计模式目录: 小菜学习设计模式(一)—模板方法(Template)模式 小菜学习设计模式(二)—单例(Singleton)模式 小菜学习设计模式(三)—工厂方法(Factory Method) ...

  3. 设置SharePoint Server 2013 的匿名访问

    默认情况下,SharePoint Server 2013 是关闭匿名访问的,但是某些环境下我们又需要将这个匿名访问对全员开放,怎么操作更加安全与便捷,对于一个崭新的环境我们可以这样操作. 首先在当前需 ...

  4. Spring配置c3p0数据源时出错报:java.lang.NoClassDefFoundError: com/mchange/v2/ser/Indirector

    今天在使用Spring配置c3p0数据源时,使用的数据库是mysql,服务器是tomcat,运行时报了一个 java.lang.NoClassDefFoundError: com/mchange/v2 ...

  5. PHP运行及语句

    php开发网页需要存放在wamp根目录下的www文件夹中才可运行成功.同时wamp要处于运行状态. 无站点情况下打开方式: 网址栏中输入:localhost/文件名称 代码规范: 用<?php ...

  6. JS实现输入框只能输入数字

    键盘下落事件实现输入框只能输入数字: <script type="text/javascript"> // 实现输入框只能输入数字 function ValidateN ...

  7. 基于OpenSLL的RSA加密应用(非算法)

    基于OpenSLL的RSA加密应用(非算法) iOS开发中的小伙伴应该是经常用der和p12进行加密解密,而且在通常加密不止一种加密算法,还可以加点儿盐吧~本文章主要阐述的是在iOS中基于openSL ...

  8. Nancy之结合tinyfox给我们的应用提供简单的数据服务

    说到提供数据服务给我们的一些应用,估计用的最多的也就是json和xml这两种数据格式 实现的方法也是多种多样,web api,mvc的jsonresult和contentresult...等等 本文是 ...

  9. C#冒泡排序法

    基本原理 比较两个相邻的数的大小,每次比较完后把最大的数放到本轮的末尾.假设有数组: 258,445,131,97,22,36,17,38,28,28,第一轮:258和445比较,位置不用交换.第二轮 ...

  10. javascript超过容器后显示省略号效果(兼容一行或者多行)

    javascript超过容器后显示省略号效果       在实际的项目中,由于文字内容的长度不确定性和页面布局的固定性,难免会出现文字内容超过div(或其他标签,下同)区域的情况,此时比较好的做法就是 ...