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

相关文章

C#实现将Excel表格转换为图片(JPG/ PNG)

《C#实现将Excel表格转换为图片(JPG/PNG)》Excel表格可能会因为不同设备或字体缺失等问题,导致格式错乱或数据显示异常,转换为图片后,能确保数据的排版等保持一致,下面我们看看如何使用C... 目录通过C# 转换Excel工作表到图片通过C# 转换指定单元格区域到图片知识扩展C# 将 Excel

Java字符串处理全解析(String、StringBuilder与StringBuffer)

《Java字符串处理全解析(String、StringBuilder与StringBuffer)》:本文主要介绍Java字符串处理全解析(String、StringBuilder与StringBu... 目录Java字符串处理全解析:String、StringBuilder与StringBuffer一、St

浅析Java中如何优雅地处理null值

《浅析Java中如何优雅地处理null值》这篇文章主要为大家详细介绍了如何结合Lambda表达式和Optional,让Java更优雅地处理null值,感兴趣的小伙伴可以跟随小编一起学习一下... 目录场景 1:不为 null 则执行场景 2:不为 null 则返回,为 null 则返回特定值或抛出异常场景

JS+HTML实现在线图片水印添加工具

《JS+HTML实现在线图片水印添加工具》在社交媒体和内容创作日益频繁的今天,如何保护原创内容、展示品牌身份成了一个不得不面对的问题,本文将实现一个完全基于HTML+CSS构建的现代化图片水印在线工具... 目录概述功能亮点使用方法技术解析延伸思考运行效果项目源码下载总结概述在社交媒体和内容创作日益频繁的

深入理解Apache Kafka(分布式流处理平台)

《深入理解ApacheKafka(分布式流处理平台)》ApacheKafka作为现代分布式系统中的核心中间件,为构建高吞吐量、低延迟的数据管道提供了强大支持,本文将深入探讨Kafka的核心概念、架构... 目录引言一、Apache Kafka概述1.1 什么是Kafka?1.2 Kafka的核心概念二、Ka

使用Node.js制作图片上传服务的详细教程

《使用Node.js制作图片上传服务的详细教程》在现代Web应用开发中,图片上传是一项常见且重要的功能,借助Node.js强大的生态系统,我们可以轻松搭建高效的图片上传服务,本文将深入探讨如何使用No... 目录准备工作搭建 Express 服务器配置 multer 进行图片上传处理图片上传请求完整代码示例

resultMap如何处理复杂映射问题

《resultMap如何处理复杂映射问题》:本文主要介绍resultMap如何处理复杂映射问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录resultMap复杂映射问题Ⅰ 多对一查询:学生——老师Ⅱ 一对多查询:老师——学生总结resultMap复杂映射问题

基于Python实现高效PPT转图片工具

《基于Python实现高效PPT转图片工具》在日常工作中,PPT是我们常用的演示工具,但有时候我们需要将PPT的内容提取为图片格式以便于展示或保存,所以本文将用Python实现PPT转PNG工具,希望... 目录1. 概述2. 功能使用2.1 安装依赖2.2 使用步骤2.3 代码实现2.4 GUI界面3.效

Python实现AVIF图片与其他图片格式间的批量转换

《Python实现AVIF图片与其他图片格式间的批量转换》这篇文章主要为大家详细介绍了如何使用Pillow库实现AVIF与其他格式的相互转换,即将AVIF转换为常见的格式,比如JPG或PNG,需要的小... 目录环境配置1.将单个 AVIF 图片转换为 JPG 和 PNG2.批量转换目录下所有 AVIF 图

详解如何通过Python批量转换图片为PDF

《详解如何通过Python批量转换图片为PDF》:本文主要介绍如何基于Python+Tkinter开发的图片批量转PDF工具,可以支持批量添加图片,拖拽等操作,感兴趣的小伙伴可以参考一下... 目录1. 概述2. 功能亮点2.1 主要功能2.2 界面设计3. 使用指南3.1 运行环境3.2 使用步骤4. 核