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

界面效果

应用的权限

 <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框架

下载地址:



  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值