iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android添加图片到ListView或者RecyclerView显示
  • 885
分享到

Android添加图片到ListView或者RecyclerView显示

图片recyclerviewlistviewAndroid 2022-06-06 07:06:14 885人浏览 泡泡鱼
摘要

先上图   点击+号就去选择图片 实际上这个添加本身就是一个ListView或者 RecyclerView 只是布局有些特殊 item  <

先上图

 

点击+号就去选择图片

实际上这个添加本身就是一个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;

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));
  
  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

您可能感兴趣的文章:浅谈RecyclerView(完美替代ListView,GridView)Android中实现淘宝购物车RecyclerView或LIstView的嵌套选择的逻辑Android RecyclerView详解之实现 ListView GridView瀑布流效果将替代ListView的RecyclerView 的使用详解(一)Android App开发中使用RecyclerView替代ListView的实践Android仿XListView支持下拉刷新和上划加载更多的自定义RecyclerView学习Android Material Design(RecyclerView代替ListView)RecyclerView使用详解(代替ListView)


--结束END--

本文标题: Android添加图片到ListView或者RecyclerView显示

本文链接: https://www.lsjlt.com/news/24329.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Android用RecyclerView实现动态添加本地图片
    本文介绍了Android用RecyclerView实现动态添加本地图片,分享给大家,具体如下:本文所用的多图选择的library来自:https://github.com/lovetuzitong/MultiImageSelector简单介...
    99+
    2023-05-30
    android 动态 添加图片
  • nginx解决图片显示过慢,或者不显示
    问题定位 经过一系列的排查(中间过程我就省略了,直接写重点了!),最终定位到是Nginx的问题。当我打开这位读者的网站后台管理系统,发现图片显示非常慢,在Nginx前端代理上查出如下错误信息。 [error] 28423#0: *5 c...
    99+
    2023-09-10
    nginx 服务器 运维 Powered by 金山文档
  • android加载系统相册图片并显示详解
    1,下载ImageLoad.jar包放入项目libs文件夹中,并点击右键—>add as Library 2,首先记得在Manifest.xml注册权限(注:6.0以后的版本要...
    99+
    2024-04-02
  • Android加载html中svg格式图片进行显示
    最近做的一个项目是把assets目录中的html显示出来,但是因为html里面有一些工程图片,虽然我用ViewPager和PhotoView,进行显示放大了,但是因为工程图片的线条较多还是比较模糊.所以后来就想用svg图片来进行显示,至于s...
    99+
    2023-05-31
    android html svg
  • android如何加载系统相册图片并显示
    这期内容当中小编将会给大家带来有关android如何加载系统相册图片并显示,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。1,下载ImageLoad.jar包放入项目libs文件夹中,并点击右键—>a...
    99+
    2023-06-22
  • Android中怎么实现图片压缩并加载显示
    这篇文章将为大家详细讲解有关Android中怎么实现图片压缩并加载显示,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。解析:图片压缩的关键就是options.inSampleSize ...
    99+
    2023-05-30
    android
  • Android 图片保存到相册不显示的解决方案(兼容Android 10及更高版本)
    目录前言问题解决问题前言 写了一个demo,简单逻辑就是:在一个图片上添加一行文字或者是水印,并且保存到系统相册,也就是我们手机上的图库。前面编辑图片添加水印都没有问题,到后面保存...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作