• Android使用开源框架加载图片


    Android开发时,有时候需要们来加载网络图片,我们可以通过api的方式进行加载,但是前几天做的时候,发现了一个优秀的开源框架,可以帮助我们非常简单便捷的进行图片的加载,所以记录一下。

    我所用的是:

    android-smart-image-view

    在github上的地址是:https://github.com/loopj/android-smart-image-view,我们可以直接进行搜索,github对于我们程序员来说简直是宝库啊,一定要能够擅长应用。

    下载下来后,我们把其目录下的src下的以com开头的文件夹拷贝到我们工程中,这样我们就能引用相应的方法了。

    由于我们要显示一整图片,所以这里在main.xml中我们需要定义的组件是。

    这里要看清楚,我的imageview不是系统api下的imageview而是引用的刚才下载的开源的smartimageview,所以这里的组件定义方式步以前的不一样,这要能记着。

    复制代码
        <com.loopj.android.image.SmartImageView
            android:id="@+id/siv"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <EditText
            android:text=""
            android:id="@+id/et_path"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="请输入图片位置" />
        
        <Button
            android:onClick="click"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="浏览" />
    复制代码

    然后再acvity中,我们这样进行按钮点击时间的实现。

    这里调用的方法setImageUrl(String url, final Integer fallbackResource, final Integer loadingResource)

    url:获取网络图片的地址。

    fallbackResource:下载失败显示的图片

    loadingResource:下载中显示的图片。

      public void click(View view){
            SmartImageView siv = (SmartImageView) findViewById(R.id.siv);
            siv.setImageUrl(et_path.getText().toString().trim()
                    ,R.drawable.ic_launcher,R.drawable.ic_launcher);
        }

    这样很简单的,我们就实现了,网络图片的加载。

    作者:Darren

    微博:@IT_攻城师

    github:@Darren90

    出处:http://www.cnblogs.com/fengtengfei/

  • 相关阅读:
    JS判断浏览器类型及版本
    php函数ob_start()、ob_end_clean()、ob_get_contents()
    HTML-embed标签详解
    QQ一键登录功能的实现过程
    windows 7系统搭建本地SVN服务器的过程
    php 环境工具官网地址
    yii2 auth access-token
    使用Yii2时遇到的实际问题
    PHPExcel正确读取excel表格时间单元格(转载)
    持续集成 Jenkins
  • 原文地址:https://www.cnblogs.com/daishuguang/p/3991590.html
Copyright © 2020-2023  润新知