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

相关文章

Java docx4j高效处理Word文档的实战指南

《Javadocx4j高效处理Word文档的实战指南》对于需要在Java应用程序中生成、修改或处理Word文档的开发者来说,docx4j是一个强大而专业的选择,下面我们就来看看docx4j的具体使用... 目录引言一、环境准备与基础配置1.1 Maven依赖配置1.2 初始化测试类二、增强版文档操作示例2.

MyBatis-Plus通用中等、大量数据分批查询和处理方法

《MyBatis-Plus通用中等、大量数据分批查询和处理方法》文章介绍MyBatis-Plus分页查询处理,通过函数式接口与Lambda表达式实现通用逻辑,方法抽象但功能强大,建议扩展分批处理及流式... 目录函数式接口获取分页数据接口数据处理接口通用逻辑工具类使用方法简单查询自定义查询方法总结函数式接口

MySQL 迁移至 Doris 最佳实践方案(最新整理)

《MySQL迁移至Doris最佳实践方案(最新整理)》本文将深入剖析三种经过实践验证的MySQL迁移至Doris的最佳方案,涵盖全量迁移、增量同步、混合迁移以及基于CDC(ChangeData... 目录一、China编程JDBC Catalog 联邦查询方案(适合跨库实时查询)1. 方案概述2. 环境要求3.

SpringBoot3.X 整合 MinIO 存储原生方案

《SpringBoot3.X整合MinIO存储原生方案》本文详细介绍了SpringBoot3.X整合MinIO的原生方案,从环境搭建到核心功能实现,涵盖了文件上传、下载、删除等常用操作,并补充了... 目录SpringBoot3.X整合MinIO存储原生方案:从环境搭建到实战开发一、前言:为什么选择MinI

SpringBoot结合Docker进行容器化处理指南

《SpringBoot结合Docker进行容器化处理指南》在当今快速发展的软件工程领域,SpringBoot和Docker已经成为现代Java开发者的必备工具,本文将深入讲解如何将一个SpringBo... 目录前言一、为什么选择 Spring Bootjavascript + docker1. 快速部署与

浅析Spring如何控制Bean的加载顺序

《浅析Spring如何控制Bean的加载顺序》在大多数情况下,我们不需要手动控制Bean的加载顺序,因为Spring的IoC容器足够智能,但在某些特殊场景下,这种隐式的依赖关系可能不存在,下面我们就来... 目录核心原则:依赖驱动加载手动控制 Bean 加载顺序的方法方法 1:使用@DependsOn(最直

Android ClassLoader加载机制详解

《AndroidClassLoader加载机制详解》Android的ClassLoader负责加载.dex文件,基于双亲委派模型,支持热修复和插件化,需注意类冲突、内存泄漏和兼容性问题,本文给大家介... 目录一、ClassLoader概述1.1 类加载的基本概念1.2 android与Java Class

基于Python实现一个图片拆分工具

《基于Python实现一个图片拆分工具》这篇文章主要为大家详细介绍了如何基于Python实现一个图片拆分工具,可以根据需要的行数和列数进行拆分,感兴趣的小伙伴可以跟随小编一起学习一下... 简单介绍先自己选择输入的图片,默认是输出到项目文件夹中,可以自己选择其他的文件夹,选择需要拆分的行数和列数,可以通过

Python使用vllm处理多模态数据的预处理技巧

《Python使用vllm处理多模态数据的预处理技巧》本文深入探讨了在Python环境下使用vLLM处理多模态数据的预处理技巧,我们将从基础概念出发,详细讲解文本、图像、音频等多模态数据的预处理方法,... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

Knife4j+Axios+Redis前后端分离架构下的 API 管理与会话方案(最新推荐)

《Knife4j+Axios+Redis前后端分离架构下的API管理与会话方案(最新推荐)》本文主要介绍了Swagger与Knife4j的配置要点、前后端对接方法以及分布式Session实现原理,... 目录一、Swagger 与 Knife4j 的深度理解及配置要点Knife4j 配置关键要点1.Spri