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

相关文章

Spring Boot @RestControllerAdvice全局异常处理最佳实践

《SpringBoot@RestControllerAdvice全局异常处理最佳实践》本文详解SpringBoot中通过@RestControllerAdvice实现全局异常处理,强调代码复用、统... 目录前言一、为什么要使用全局异常处理?二、核心注解解析1. @RestControllerAdvice2

Linux中压缩、网络传输与系统监控工具的使用完整指南

《Linux中压缩、网络传输与系统监控工具的使用完整指南》在Linux系统管理中,压缩与传输工具是数据备份和远程协作的桥梁,而系统监控工具则是保障服务器稳定运行的眼睛,下面小编就来和大家详细介绍一下它... 目录引言一、压缩与解压:数据存储与传输的优化核心1. zip/unzip:通用压缩格式的便捷操作2.

SQLite3 在嵌入式C环境中存储音频/视频文件的最优方案

《SQLite3在嵌入式C环境中存储音频/视频文件的最优方案》本文探讨了SQLite3在嵌入式C环境中存储音视频文件的优化方案,推荐采用文件路径存储结合元数据管理,兼顾效率与资源限制,小文件可使用B... 目录SQLite3 在嵌入式C环境中存储音频/视频文件的专业方案一、存储策略选择1. 直接存储 vs

利用Python脚本实现批量将图片转换为WebP格式

《利用Python脚本实现批量将图片转换为WebP格式》Python语言的简洁语法和库支持使其成为图像处理的理想选择,本文将介绍如何利用Python实现批量将图片转换为WebP格式的脚本,WebP作为... 目录简介1. python在图像处理中的应用2. WebP格式的原理和优势2.1 WebP格式与传统

Spring如何使用注解@DependsOn控制Bean加载顺序

《Spring如何使用注解@DependsOn控制Bean加载顺序》:本文主要介绍Spring如何使用注解@DependsOn控制Bean加载顺序,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录1.javascript 前言2. 代码实现总结1. 前言默认情况下,Spring加载Bean的顺

基于 HTML5 Canvas 实现图片旋转与下载功能(完整代码展示)

《基于HTML5Canvas实现图片旋转与下载功能(完整代码展示)》本文将深入剖析一段基于HTML5Canvas的代码,该代码实现了图片的旋转(90度和180度)以及旋转后图片的下载... 目录一、引言二、html 结构分析三、css 样式分析四、JavaScript 功能实现一、引言在 Web 开发中,

Python如何去除图片干扰代码示例

《Python如何去除图片干扰代码示例》图片降噪是一个广泛应用于图像处理的技术,可以提高图像质量和相关应用的效果,:本文主要介绍Python如何去除图片干扰的相关资料,文中通过代码介绍的非常详细,... 目录一、噪声去除1. 高斯噪声(像素值正态分布扰动)2. 椒盐噪声(随机黑白像素点)3. 复杂噪声(如伪

Python中图片与PDF识别文本(OCR)的全面指南

《Python中图片与PDF识别文本(OCR)的全面指南》在数据爆炸时代,80%的企业数据以非结构化形式存在,其中PDF和图像是最主要的载体,本文将深入探索Python中OCR技术如何将这些数字纸张转... 目录一、OCR技术核心原理二、python图像识别四大工具库1. Pytesseract - 经典O

电脑提示xlstat4.dll丢失怎么修复? xlstat4.dll文件丢失处理办法

《电脑提示xlstat4.dll丢失怎么修复?xlstat4.dll文件丢失处理办法》长时间使用电脑,大家多少都会遇到类似dll文件丢失的情况,不过,解决这一问题其实并不复杂,下面我们就来看看xls... 在Windows操作系统中,xlstat4.dll是一个重要的动态链接库文件,通常用于支持各种应用程序

SQL Server数据库死锁处理超详细攻略

《SQLServer数据库死锁处理超详细攻略》SQLServer作为主流数据库管理系统,在高并发场景下可能面临死锁问题,影响系统性能和稳定性,这篇文章主要给大家介绍了关于SQLServer数据库死... 目录一、引言二、查询 Sqlserver 中造成死锁的 SPID三、用内置函数查询执行信息1. sp_w