SmartImageView主要是为了加速从网上加载图片,支持根据URL地址加载图片,支持异步加载图片,支持图片缓存等。
下载地址 http://loopj.com/android-smart-image-view/
下载完成后拷贝到项目下的libs文件下即可。
在xml文件下添加一个SmartImageView控件
<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" >
<com.loopj.android.image.SmartImageView
android:id="@+id/sv_1"
android:layout_width="fill_parent"
android:layout_height="300dp" />
</LinearLayout>
MainActivity.class
package com.example.smartimageview;
import com.loopj.android.image.SmartImageView;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
private SmartImageView sv_1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sv_1 = (SmartImageView) findViewById(R.id.sv_1);
sv_1.setImageUrl("http://s1.dwstatic.com/lushicard/Lyra_the_Sunshard.png",//加载指定地址的图片
R.drawable.ic_launcher,//指定图片没找到时显示的图片
R.drawable.ic_launcher);//正在加载中显示的图片
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
添加访问网络的权限 android.permission.INTERNET
使用Eclipse千万别忘了权限,权限,权限。AndroidMainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.smartimageview"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.smartimageview.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
就只是简单的使用下。