增加一个自定义的View:
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.util.AttributeSet;
import com.android.volley.toolbox.NetworkImageView;
/**
* 在Volley框架的NetworkImageView的基础上增加了渐变效果
* Created by Amery on 13-11-3.
*/
public class FadeInNetworkImageView extends NetworkImageView {
private static final int FADE_IN_TIME_MS = 300;
public FadeInNetworkImageView(Context context) {
super(context);
}
public FadeInNetworkImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FadeInNetworkImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void setImageBitmap(Bitmap bm) {
TransitionDrawable td = new TransitionDrawable(new Drawable[]{
new ColorDrawable(android.R.color.transparent),
new BitmapDrawable(getContext().getResources(), bm)
});
setImageDrawable(td);
td.startTransition(FADE_IN_TIME_MS);
}
}
在xml布局中改为<com.xxx.FadeInNetworkImageView 。。。/>即可。
调用时imageView.setImageUrl(url,VolleyTool.getInstance(context).getImageLoader);即可。非常方便。
使用了一段时间的Volley框架感觉还不错,Google IO上Google Play的Manger说是所以第三方包中最快的,实际使用中感觉还行,也没觉得是最快的。可能还有一些设置要调吧。先用用,下次分享一下实际开发中的体会。