zoukankan      html  css  js  c++  java
  • 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/

  • 相关阅读:
    谷歌关闭中国区购物搜索小思考
    java生成本地头文件用javah出错问题
    hadoop源代码分析(4)org.apache.hadoop.util包GenericOptionsParser类【原创】
    Ext.util.MixedCollection 用法
    eval 函数用法
    Rails Devise_demo
    rails rake 指南
    accepts_nested_attributes_for
    将Rails3.0无缝升级到Rails3.1.0.beta1
    spork + autotest 实现rails自动化测试
  • 原文地址:https://www.cnblogs.com/daishuguang/p/3991590.html
Copyright © 2011-2022 走看看