您的位置:首页 > 理论基础 > 计算机网络

第三方开源项目加载网络图片

2015-12-17 22:23 579 查看
github加载网络图片地址:https://github.com/loopj/android-smart-image-view

直接导入自己的项目中:



效果图:

正常加载
加载失败





当加载图片出现错误时,调用setImageUrl()的后面自定义的图片(表示错误)。

activity_main:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.zhangli.lookPicture.MainActivity" >

<com.loopj.android.image.SmartImageView
android:layout_weight="1000"
android:id="@+id/siv"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<EditText
android:id="@+id/et_path"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入图片路径"
android:singleLine="true"
android:text="http://avatar.csdn.net/F/E/F/1_zhangli_.jpg" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="click"
android:text="浏览" />

</LinearLayout>


MainActivity:

package com.zhangli.imageviewer;

import com.loopj.android.image.SmartImageView;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {
private EditText et_path;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et_path=(EditText) findViewById(R.id.et_path);
}

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);
}
}


最后加上权限。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: