最近一直在学习从远程服务器获取图片,开始时都是手写这些处理,后来接触到了smartImageview这个插件。github获取地址:https://github.com/loopj/android-smart-p_w_picpath-view

官方原版插件说明

Overview

        SmartImageView is a drop-in replacement for Android’s standard ImageView which additionally allows p_w_picpaths to be loaded from URLs or the user’s contact address book. Images are cached to memory and to disk for super fast loading.


Features

    • Drop-in replacement for ImageView

    • Load p_w_picpaths from a URL

    • Load p_w_picpaths from the phone’s contact address book

    • Asynchronous loading of p_w_picpaths, loading happens outside the UI thread

    • Images are cached to memory and to disk for super fast loading

    • SmartImage class is easily extendable to load from other sources


其中用到的就是:setImageUrl()方法,该方法有好几个重载方法,用到了这个

setImageUrl(String url,int fallbackResource)

这个方法的参数解析如下:url当然是远程图片的地址,第二个参数是当获取远程图片失败时,显示的图片,是一个int类型的res下的图片的一个id


        在使用时,直接在布局文件里使用SmartImageView就行,这个类继承自ImageView

<?xml version="1.0" encoding="utf-8"?>
   xmlns:android="http://schemas.android.com/apk/res/android"

   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical">
   
           android:id="@+id/siv"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"/>

在MainActivity 中

com.yuanlp.smartp_w_picpathviewandroid.support.v7.app.AppCompatActivityandroid.os.Bundlecom.yuanlp.smartp_w_picpathview.loopj.android.p_w_picpath.SmartImageViewMainActivity AppCompatActivity {    (Bundle savedInstanceState) {        .onCreate(savedInstanceState)setContentView(R.layout.)SmartImageView siv=(SmartImageView) findViewById(R.id.)siv.setImageUrl(R.drawable.)}}



更多相关文章

  1. Android——网络编程(网络图片查看器)
  2. android用户界面之Gallery教程实例汇总
  3. android对界面某一部分进行截图的方法
  4. Android在桌面创建快捷方式
  5. Android(安卓)Studio 编译慢解决方法
  6. Android实现悬浮图片
  7. 【Android(安卓)开发教程】Fragment的生命周期
  8. Ubuntu中编译Android(安卓)JellyBean 4.2.1源码出现Switch.pm出
  9. Android(安卓)Studio 快捷键使用

随机推荐

  1. 知识星球 | 说说我为什么要做『python数
  2. 大数据告诉你,台风最喜欢在我国哪个省市登
  3. excel VS python 谁更适合数据分析?
  4. Seaborn:一行代码生成酷炫狂拽的数据集可
  5. 干货 | 使用pyecharts绘制交互式动态地图
  6. numpy 100题练习 <二>
  7. 使用requests爬取拉勾网python职位数据
  8. 影评分析 | 《小丑》,戴上快乐的笑脸
  9. 干货 | Bokeh交互式数据可视化快速入门
  10. Pandas 50题练习