SmartImageView的简单使用

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>

这里写图片描述

就只是简单的使用下。

  • 7
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值