NetworkImageView 设置默认图片

原文地址:http://stackoverflow.com/questions/21567055/display-networkimageviews-default-image-without-network-request


The problem is that even if a default image is set, it won't be displayed until one calls setImageUrl(), which in turn will set the source bitmap of the view to null if the url is empty. If the url isn't empty, it makes a request. This means that one is forced to make a network request even if there isn't a valid network url associated with that particular view, otherwise instead of displaying the default image it displays an empty view.


String url = getURL();
    NetworkImageView niv = (NetworkImageView)rootView.findViewById(R.id.niv);
    if(url.length() > 0)
        niv.setImageUrl(url, imageLoader);
    niv.setDefaultImageResId(R.drawable._default);
    niv.setErrorImageResId(R.drawable.error);


需要最新版的 volley,旧版的存在bug,不能设置

可用volley jar 下载地址 http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.mcxiaoke.volley%22


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值