Android添加图片到ListView或者 RecyclerView显示
先上图
点击+号就去选择图片
实际上这个添加本身就是一个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显示的更多相关文章
- android中ScrollView嵌套ListView或GridView显示位置问题
Android中ScrollView中嵌套ListView或GridView时在开始进入界面时总是显示中间位置,开头的位置显示不出来.这种情况下只需要在ScrollView的父控件中添加以下两行代码即 ...
- Android学习笔记:ListView简单应用--显示文字列表
在activity中的编写如下代码: final List<String> items = new ArrayList<String>(); //设置要显示的数据,这里因为是例 ...
- Android 解决ScrollView嵌入ListView | GridView | ScrollView显示问题
一.ScrollView中嵌套ListView ScrollView和ListView都是滚动结构,很明显如果在ScrollView中加入ListView,可以预见性的知道,肯定会有显示/滚动的问题, ...
- Android开发之漫漫长途 XVI——ListView与RecyclerView项目实战
该文章是一个系列文章,是本人在Android开发的漫漫长途上的一点感想和记录,我会尽量按照先易后难的顺序进行编写该系列.该系列引用了<Android开发艺术探索>以及<深入理解And ...
- android listview 替代品recyclerview详解
安卓v7支持包下的ListView替代品————RecyclerView RecyclerView这个控件也出来很久了,相信大家也学习的差不多了,如果还没学习的,或许我可以带领大家体验一把这个艺术 ...
- 【腾讯Bugly干货分享】Android ListView与RecyclerView对比浅析--缓存机制
本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/5811d3e3ab10c62013697408 作者:黄宁源 一,背景 Recy ...
- Android ListView item项 显示动画
(1)使用LayoutAnimation 所谓的布局动画,其实就是为ViewGroup添加显示动画效果,主要用过LayoutAnimationController来控制实现.LayoutAnimati ...
- android 项目学习随笔十七(ListView、GridView显示组图)
ListView.GridView显示组图,处理机制相同 <?xml version="1.0" encoding="utf-8"?> <Li ...
- Android根据Button状态(normal,focused,pressed)显示不同背景图片
Android根据Button状态(normal,focused,pressed)显示不同背景图片 Android中Button 有focused, selected, pressed 等不同状态,通 ...
随机推荐
- Power BI官方视频(1) Power BI Desktop 7月份更新功能概述
2016年7月,Power BI Desktop进行了一些功能更新,提高整体的用户体验.同时也有一些新的和令人兴奋的功能.看看大概介绍,更新功能要点: 本文原文地址:Power BI官方视频(1) P ...
- 【tomcat】不同域名解析到同一tomcat不同项目上
问题: 1. 有多个域名,想输入的每个域名只能访问其中的一个项目 2. 这些项目都部署在同一个tomcat上的 解决步骤: 1.首先把所有域名都解析到这台服务器上,解析时只能填写ip地址,不 ...
- Java内存模型深度解析:final--转
原文地址:http://www.codeceo.com/article/java-memory-6.html 与前面介绍的锁和Volatile相比较,对final域的读和写更像是普通的变量访问.对于f ...
- C# PPT 为形状设置三维效果
在PPT中,形状是非常重要的元素.3-D形状,立体多元,给人耳目一新的感觉.在幻灯片中添加3-D效果形状,必然会为PPT的整体效果增色不少.为形状设置三维格式时,可设置棱台,轮廓线,表面效果等. 本篇 ...
- 千呼万唤始出来:Apache Spark2.0正式发布
我们很荣幸地宣布,自7月26日起Databricks开始提供Apache Spark 2.0的下载,这个版本是基于社区在过去两年的经验总结而成,不但加入了用户喜爱的功能,也修复了之前的痛点. 本文总结 ...
- hdu FatMouse's Speed 动态规划DP
动态规划的解决方法是找到动态转移方程. 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3§ionid ...
- Jackson的简单用法
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1简介 Jackson具有比较高的序列化和反序列化效率,据测试,无论是 ...
- 跟我学PHP第二篇- 配置Mysql以及PHP WampServer篇(1)
大家好,昨天我给大家介绍了如何去安装ZEND STUDIO,下面昨天文章的链接: http://www.cnblogs.com/kmsfan/p/zendStudio.html 本节为配置的第一部分, ...
- Java中的反射机制
Java反射机制 反射机制定义 反射机制是Java语言中一个非常重要的特性,它允许程序在运行时进行自我检查,同时也允许其对内部成员进行操作.由于反射机制能够实现在运行时对类进行装载,因此能够增加程序的 ...
- Solr学习总结(三)Solr web 管理后台
前面讲到了Solr的安装,按道理,这次应该讲讲.net与数据库的内容,C#如何操作Solr索引等.不过我还是想先讲一些基础的内容,比如solr查询参数如何使用,各个参数都代表什么意思? 还有solr ...