博客
关于我
Picasso 用法(旧)
阅读量:129 次
发布时间:2019-02-27

本文共 2636 字,大约阅读时间需要 8 分钟。

GRADLE

dependencies {       compile 'com.squareup.picasso:picasso:2.5.1'}

在AndroidManifest.xml中添加INTERNET权限:

给ImageView添加网络图片:

在MainActivity.java中添加

ImageView img = (ImageView)findViewById(R.id.picture);Picasso.with(this).load("https://www.baidu.com/img/bd_logo1.png?where=super").into(img);

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Adapter中使用Picasso

MainActivity传this,赋值mContext

MainActivity.java

MyListAdapter myListAdapter = new MyListAdapter(this,list);

ListAdapter.java

List
mList; private Context mContext; private LayoutInflater myLayoutInflater; public MyListAdapter(Context context,List
list){ mList = list; myLayoutInflater = LayoutInflater.from(context); mContext = context; }

优化

public View getView(int i, View view, ViewGroup viewGroup) {           ViewHolder holder;        ItemBean item = mList.get(i);        if(view==null){               view=myLayoutInflater.inflate(R.layout.activity_items,null);            holder= new ViewHolder();            holder.imageView = (ImageView)view.findViewById(R.id.picture);            holder.title = (TextView)view.findViewById(R.id.tv1);            holder.content = (TextView)view.findViewById(R.id.tv2);            view.setTag(holder);        }        else {               holder = (ViewHolder) view.getTag();        }        holder.title.setText(item.getItemTitle());        holder.content.setText(item.getItemContent());        //holder.imageView.setImageResource(item.getItemImageResourceId());        //改成利用Picasso框架加载图片        Picasso.with(mContext).load(item.getItemImageResourceId()).into(holder.imageView);        view.setBackgroundResource(item.getBackgroundColor());        return view;    }

ItemBean.java

public class ItemBean{       private int ItemImageResourceId;    private String ItemTitle;    private String ItemContent;    private int BackgroundColor;    public ItemBean(int itemImageResourceId, String itemTitle,String itemContent,int backgroundColor){           this.ItemImageResourceId = itemImageResourceId;        this.ItemTitle = itemTitle;        this.ItemContent = itemContent;        this.BackgroundColor = backgroundColor;    }    public String getItemTitle(){           return ItemTitle;    }    public String getItemContent(){           return ItemContent;    }    public int getItemImageResourceId(){           return ItemImageResourceId;    }    public int getBackgroundColor(){           return BackgroundColor;    }}

网站:

转载地址:http://zcob.baihongyu.com/

你可能感兴趣的文章
Mysql学习总结(22)——Mysql数据库中制作千万级测试表
查看>>
Mysql学习总结(23)——MySQL统计函数和分组查询
查看>>
Mysql学习总结(24)——MySQL多表查询合并结果和内连接查询
查看>>
Mysql学习总结(25)——MySQL外连接查询
查看>>
Mysql学习总结(26)——MySQL子查询
查看>>
Mysql学习总结(27)——Mysql数据库字符串函数
查看>>
Mysql学习总结(28)——MySQL建表规范与常见问题
查看>>
Mysql学习总结(29)——MySQL中CHAR和VARCHAR
查看>>
Mysql学习总结(2)——Mysql超详细Window安装教程
查看>>
Mysql学习总结(30)——MySQL 索引详解大全
查看>>
Mysql学习总结(31)——MySql使用建议,尽量避免这些问题
查看>>
Mysql学习总结(32)——MySQL分页技术详解
查看>>
Mysql学习总结(33)——阿里云centos配置MySQL主从复制
查看>>
Mysql学习总结(35)——Mysql两千万数据优化及迁移
查看>>
Mysql学习总结(36)——Mysql查询优化
查看>>
Mysql学习总结(37)——Mysql Limit 分页查询优化
查看>>
Mysql学习总结(38)——21条MySql性能优化经验
查看>>
Mysql学习总结(39)——49条MySql语句优化技巧
查看>>
Mysql学习总结(3)——MySql语句大全:创建、授权、查询、修改等
查看>>
Mysql学习总结(40)——MySql之Select用法汇总
查看>>