用开源代码smartimageview 实现网络图片查看

1.下载开源代码

 

 

 

1. 布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <com.loopj.android.image.SmartImageView
        android:layout_weight="200"
        android:id="@+id/image"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
         />
    <EditText
        android:id="@+id/path"
        android:lines="1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="请输入浏览图片的地址"
         />
    <Button
        android:id="@+id/button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="浏览"
        android:onClick="onClick"
         />
</LinearLayout>


 

MainActivity.java

package com.example.image;

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

public class MainActivity extends Activity {
	private EditText path;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		path = (EditText) findViewById(R.id.path);
		path.setText("http://10.162.0.171:8080/Image/image.png");
	}

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

	public void onClick(View view) {
		String imagePath = path.getText().toString().trim();
		// 开源代码实现好的SmartImageView
		SmartImageView imageView = (SmartImageView) findViewById(R.id.image);
		// setImageUrl(String url, Integer fallbackResource, Integer
		// loadingResource)
		// fallbackResource:图片下载失败时显示的图片 loadingResource:图片正在下载显示的图片
		imageView.setImageUrl(imagePath, R.drawable.ic_launcher,
				R.drawable.ic_launcher);
	}
}


 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值