[android] smartimageview&常见的开源代码

github上搜索开源框架android-smarty-imageview,下载压缩包,拷贝我们之前写的网络图片查看器布局。

 

解压下载包里面的数据,找到java源码拷贝到我们的项目里,这时我们可以看到这个包下面有个SmartyImageView.java的自定义控件,SmartImageView是继承自ImageView

 

当我们在布局文件中使用ImageView时,可以直接写,那是因为这个类是包含在android.jar的包里面,使用自定义的时候,一定要加上包名

 

获取SmartImageView对象,通过findViewById()方法

调用SmartImageView对象的setImageUrl(url,fallbackResource,loadingResource)方法,参数:urlString类型的图片路径,另两个一个是下载失败时显示和正在下载时显示的int类型的资源id

 

package com.tsh.smartimageview;

import com.loopj.android.image.SmartImageView;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {
    private EditText et_path;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        et_path=(EditText) findViewById(R.id.et_path);
    }
    public void getInternetImg(View v){
        SmartImageView siv=(SmartImageView) findViewById(R.id.siv_pic);
        siv.setImageUrl(et_path.getText().toString().trim(), R.drawable.ic_launcher, R.drawable.ic_launcher);
    }
}

 

posted @ 2016-03-22 21:31  唯一客服系统开发笔记  阅读(356)  评论(0编辑  收藏  举报