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 等不同状态,通 ...
随机推荐
- jQuery.unique引发一个血案
项目开发过程中,PM说系统只要在一个特定的浏览器中运行就好,但是在其他的浏览器中不能出现逻辑的错误,所以在开发过程中,前端和后台选择是Chrome浏览器,没有仔细测试Firefox和IE.但是昨天PM ...
- iOS开发之手势识别
感觉有必要把iOS开发中的手势识别做一个小小的总结.在上一篇iOS开发之自定义表情键盘(组件封装与自动布局)博客中用到了一个轻击手势,就是在轻击TextView时从表情键盘回到系统键盘,在TextVi ...
- 真正解决问题:maven eclipse tomcat java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener--转
原文地址:http://www.cnblogs.com/amosli/p/4067665.html 在使用eclipse进行整合springmvc时经常会碰到这样的异常: java.lang.Clas ...
- jdk线程池主要原理
本文转自:http://blog.csdn.net/linchengzhi/article/details/7567397 正常创建一个线程的时候,我们是这样的:new thread(Runnable ...
- 初来乍到 Java 和 .Net 迭代器功能
最近有一个需求是这样的, 根据键值对存储类型数据,也算是数据缓存块模块功能设计. 一个键对应多个值.每一个键的值类型相同,但是每个不同的键之间类型不一定相同. Java 设计如下 HashMap< ...
- CSS魔法堂:重拾Border之——更广阔的遐想
前言 当CSS3推出border-radius属性时我们是那么欣喜若狂啊,一想到终于不用再添加额外元素来模拟圆角了,但发现border-radius还分水平半径和垂直半径,然后又发现border-t ...
- webpack+vue-cli项目打包技巧
1.设置config文件夹index.js中productionSourceMap的值为false,也就是设置webpack配置中devtool为false,打包后文件体积可以减少百分之八十!!!!! ...
- Rafy 中的 Linq 查询支持(根据聚合子条件查询聚合父)
为了提高开发者的易用性,Rafy 领域实体框架在很早开始就已经支持使用 Linq 语法来查询实体了.但是只支持了一些简单的.常用的条件查询,支持的力度很有限.特别是遇到对聚合对象的查询时,就不能再使用 ...
- Android封装OkHttpClient的类库
由于android6.0的SDK没有HttpClient,只有HttpURLConnection和OkHttpClient,特记下OkHttpClient的使用方法 1.Ui测试界面布局 <?x ...
- OA项目——总结
先来张大致结构图: 项目链接:https://github.com/shuai7boy/YM_OA