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

Android-smart-image-view加载网络图片

2014-05-30 15:30 721 查看
界面效果



应用的权限

 <uses-permission android:name="android.permission.INTERNET"/>

布局文件

<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=".MainActivity" >

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

<EditText
android:id="@+id/et_path"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入图片地址"
android:singleLine="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="checkImage"
android:text="@string/bt_catchImage" />

</LinearLayout>


核心文件

package com.examp.use_android_smart_image_view;

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;
private SmartImageView siv;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et_path = (EditText) findViewById(R.id.et_path);
et_path.setText("http://c.hiphotos.baidu.com/image/w%3D310/sign=1ebfb751a6c27d1ea5263dc52bd4adaf/78310a55b319ebc47dc5736c8026cffc1f171681.jpg");

}

public void checkImage(View view) {
siv = (SmartImageView) findViewById(R.id.siv);

// 加载的路径|如果没有加载到显示的内容|等待加载的图片
siv.setImageUrl(et_path.getText().toString().trim(),
R.drawable.ic_launcher, R.drawable.ic_launcher);
}

}

注:使用前提,需要加入Android-smart-image-view框架



下载地址:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Android基础