ImageView simpleAdapter 加载网络图片的处理方案

2023-12-03 09:48

本文主要是介绍ImageView simpleAdapter 加载网络图片的处理方案,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

ImageView simpleAdapter 加载网络图片的处理方案

文章目录

  • ImageView simpleAdapter 加载网络图片的处理方案
      • 1、下载smartImageView
      • 2、使用smartImageView标签
      • 3 修改数据绑定方式
      • 4 将数据绑定方式注册到simpleAdapter中

背景:最近做一个安卓的app软件,由于android只能使用本地的照片,和数据库设计本省有点出入,让我头有点疼;通过万能的百娘,我快速锁定一个smartImageView的插件。可以直接使用url的方式显示图片。

先看效果图:

在这里插入图片描述

数据格式:

[{"dateTime": "2020-04-16T05:38:35.000+0000","image": "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1587032030220&di=bfc40a54c3c376905f4ff044a149f6aa&imgtype=0&src=http%3A%2F%2Fimage.tianjimedia.com%2FuploadImages%2F2015%2F295%2F41%2F0E87XZ5MPO7J_3epECXX_600.jpg","name": "00000000012","count": 1,"x": "12313212","y": "1212121","id": "1173865949930065920"
}, {"dateTime": "2020-04-16T05:38:38.000+0000","image": "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1587032030220&di=bfc40a54c3c376905f4ff044a149f6aa&imgtype=0&src=http%3A%2F%2Fimage.tianjimedia.com%2FuploadImages%2F2015%2F295%2F41%2F0E87XZ5MPO7J_3epECXX_600.jpg","name": "00000000013","count": 1,"x": "21313112","y": "3123213","id": "1173865949930065921"
}]

1、下载smartImageView

git:https://github.com/JackCho/SmartImageView

下载后将文件src下文件放入到自己的 工程目录中。

2、使用smartImageView标签

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:orientation="horizontal"android:layout_width="match_parent"android:layout_height="match_parent"><com.loopj.android.image.SmartImageViewandroid:id="@+id/shebei_item_image"android:layout_width="80dp"android:layout_height="80dp"app:srcCompat="@drawable/button_bg" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal"><TextViewandroid:id="@+id/textView8"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="序号" /><TextViewandroid:id="@+id/shebei_item_id"android:layout_width="wrap_content"android:layout_height="wrap_content" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal"><TextViewandroid:id="@+id/textView9"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="总数量" /><TextViewandroid:id="@+id/shebei_item_count"android:layout_width="wrap_content"android:layout_height="wrap_content"android:singleLine="true" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal"><TextViewandroid:id="@+id/textView10"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="设备名称" /><TextViewandroid:id="@+id/shebei_item_name"android:layout_width="wrap_content"android:layout_height="wrap_content" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal"><TextViewandroid:id="@+id/textView11"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="入网时间" /><TextViewandroid:id="@+id/shebei_item_dateTime"android:layout_width="wrap_content"android:layout_height="wrap_content" /></LinearLayout></LinearLayout></LinearLayout>

3 修改数据绑定方式


package com.liu.znybq.adapter;import android.view.View;
import android.widget.ImageView;
import android.widget.SimpleAdapter;import com.liu.znybq.utils.L;
import com.loopj.android.image.SmartImage;
import com.loopj.android.image.SmartImageView;/**  项目名:  android_znybq*  包名:     com.liu.znybq.adapter*  文件名:    CustomImageViewBinder*  创建者:    shi860715@126.com liubj*  创建时间:   2020/4/16  15:54*  描述:    用来处理照片*/
public class CustomImageViewBinder  implements SimpleAdapter.ViewBinder {@Overridepublic boolean setViewValue(View view, Object data, String textRepresentation) {if( view instanceof SmartImageView){((SmartImageView) view).setImageUrl(data.toString());return  true;}return false;}
}

修改数据和视图的绑定方式;

4 将数据绑定方式注册到simpleAdapter中

simpleAdapter = new MySimpleAdapter(getActivity(),list,R.layout.shebei_item,new String[]{"id","name","count","dateTime","image"},new int[]{R.id.shebei_item_id,R.id.shebei_item_name,R.id.shebei_item_count,R.id.shebei_item_dateTime,R.id.shebei_item_image});simpleAdapter.setViewBinder(new CustomImageViewBinder());listView.setAdapter(simpleAdapter);

这篇关于ImageView simpleAdapter 加载网络图片的处理方案的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/448985

相关文章

SpringBoot分段处理List集合多线程批量插入数据方式

《SpringBoot分段处理List集合多线程批量插入数据方式》文章介绍如何处理大数据量List批量插入数据库的优化方案:通过拆分List并分配独立线程处理,结合Spring线程池与异步方法提升效率... 目录项目场景解决方案1.实体类2.Mapper3.spring容器注入线程池bejsan对象4.创建

PHP轻松处理千万行数据的方法详解

《PHP轻松处理千万行数据的方法详解》说到处理大数据集,PHP通常不是第一个想到的语言,但如果你曾经需要处理数百万行数据而不让服务器崩溃或内存耗尽,你就会知道PHP用对了工具有多强大,下面小编就... 目录问题的本质php 中的数据流处理:为什么必不可少生成器:内存高效的迭代方式流量控制:避免系统过载一次性

MyBatis Plus实现时间字段自动填充的完整方案

《MyBatisPlus实现时间字段自动填充的完整方案》在日常开发中,我们经常需要记录数据的创建时间和更新时间,传统的做法是在每次插入或更新操作时手动设置这些时间字段,这种方式不仅繁琐,还容易遗漏,... 目录前言解决目标技术栈实现步骤1. 实体类注解配置2. 创建元数据处理器3. 服务层代码优化填充机制详

防止Linux rm命令误操作的多场景防护方案与实践

《防止Linuxrm命令误操作的多场景防护方案与实践》在Linux系统中,rm命令是删除文件和目录的高效工具,但一旦误操作,如执行rm-rf/或rm-rf/*,极易导致系统数据灾难,本文针对不同场景... 目录引言理解 rm 命令及误操作风险rm 命令基础常见误操作案例防护方案使用 rm编程 别名及安全删除

Python实现批量CSV转Excel的高性能处理方案

《Python实现批量CSV转Excel的高性能处理方案》在日常办公中,我们经常需要将CSV格式的数据转换为Excel文件,本文将介绍一个基于Python的高性能解决方案,感兴趣的小伙伴可以跟随小编一... 目录一、场景需求二、技术方案三、核心代码四、批量处理方案五、性能优化六、使用示例完整代码七、小结一、

Python中 try / except / else / finally 异常处理方法详解

《Python中try/except/else/finally异常处理方法详解》:本文主要介绍Python中try/except/else/finally异常处理方法的相关资料,涵... 目录1. 基本结构2. 各部分的作用tryexceptelsefinally3. 执行流程总结4. 常见用法(1)多个e

Java实现将HTML文件与字符串转换为图片

《Java实现将HTML文件与字符串转换为图片》在Java开发中,我们经常会遇到将HTML内容转换为图片的需求,本文小编就来和大家详细讲讲如何使用FreeSpire.DocforJava库来实现这一功... 目录前言核心实现:html 转图片完整代码场景 1:转换本地 HTML 文件为图片场景 2:转换 H

C#使用Spire.Doc for .NET实现HTML转Word的高效方案

《C#使用Spire.Docfor.NET实现HTML转Word的高效方案》在Web开发中,HTML内容的生成与处理是高频需求,然而,当用户需要将HTML页面或动态生成的HTML字符串转换为Wor... 目录引言一、html转Word的典型场景与挑战二、用 Spire.Doc 实现 HTML 转 Word1

PHP应用中处理限流和API节流的最佳实践

《PHP应用中处理限流和API节流的最佳实践》限流和API节流对于确保Web应用程序的可靠性、安全性和可扩展性至关重要,本文将详细介绍PHP应用中处理限流和API节流的最佳实践,下面就来和小编一起学习... 目录限流的重要性在 php 中实施限流的最佳实践使用集中式存储进行状态管理(如 Redis)采用滑动

Java实现在Word文档中添加文本水印和图片水印的操作指南

《Java实现在Word文档中添加文本水印和图片水印的操作指南》在当今数字时代,文档的自动化处理与安全防护变得尤为重要,无论是为了保护版权、推广品牌,还是为了在文档中加入特定的标识,为Word文档添加... 目录引言Spire.Doc for Java:高效Word文档处理的利器代码实战:使用Java为Wo