如何在加载之前为卸载的图像视图提供不同的颜色,更改 Picasso 代码以滑动
How to give unloaded imageview different colors until they are loaded, change Picasso code to glide
使用 Picasso 很容易实现
Picasso.with(holder.mImageView.getContext())
.load(item.getUrl())
.into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
holder.mImageView.setImageBitmap(bitmap);
holder.mLoadingImageView.setVisibility(View.GONE);
holder.updatePalette();//the logic of generate diffrent background colors
Log.d(TAG, "on success");
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
holder.mLoadingImageView.setVisibility(View.GONE);
Log.d(TAG, "on error");
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
holder.mLoadingImageView.setVisibility(View.VISIBLE);
}
});
和 holder
从 updatePalette
函数处理 that logic
(为卸载的图像获取不同的颜色),here its code or the whole demo 如果需要
在滑翔什么?
Glide.with(holder.mImageView.getContext())
.load(item.getUrl())
.into(/*WHAT*/);
任何重复都会有所帮助。
placeholder Image设置方法Picasso
和Glid
相同
滑行
Glide.with(holder.mImageView.getContext())
.load(item.getUrl())
.placeholder(R.drawable.placeholder)
.into(imageView)
毕加索
Picasso.with(holder.mImageView.getContext())
.load(item.getUrl())
.placeholder(R.drawable.placeholder)
.into(imageView)
您可以在 glide 中使用 Target or SimpleTarget (implements Target) 实现相同的效果。
即
Glide.load("http://somefakeurl.com/fakeImage.jpeg")
.asBitmap()
.fitCenter()
.into(new SimpleTarget(250, 250) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
// Image Loaded successfully.
}
@Override
public void onLoadStarted(Drawable placeholder){
// Image Loading starts
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable){
// Image Loading failed
}
});
}
使用 Picasso 的占位符功能保留 PlaceHolder 直到加载图像
Picasso.with(context)
.load("image_url")
.placeholder(R.drawable.ic_launcher)
.into(imageView);
最后我做到了
private ColorDrawable[] vibrantLightColorList =
{
new ColorDrawable(Color.parseColor("#9ACCCD")), new ColorDrawable(Color.parseColor("#8FD8A0")),
new ColorDrawable(Color.parseColor("#CBD890")), new ColorDrawable(Color.parseColor("#DACC8F")),
new ColorDrawable(Color.parseColor("#D9A790")), new ColorDrawable(Color.parseColor("#D18FD9")),
new ColorDrawable(Color.parseColor("#FF6772")), new ColorDrawable(Color.parseColor("#DDFB5C"))
};
然后
Glide.with(holder.mImageView.getContext())
.load(item.getUrl())
.placeholder(getRandomDrawbleColor())
.into(holder.mImageView);
和
public ColorDrawable getRandomDrawbleColor() {
int idx = new Random().nextInt(vibrantLightColorList.length);
return vibrantLightColorList[idx];
}
使用 Picasso 很容易实现
Picasso.with(holder.mImageView.getContext())
.load(item.getUrl())
.into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
holder.mImageView.setImageBitmap(bitmap);
holder.mLoadingImageView.setVisibility(View.GONE);
holder.updatePalette();//the logic of generate diffrent background colors
Log.d(TAG, "on success");
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
holder.mLoadingImageView.setVisibility(View.GONE);
Log.d(TAG, "on error");
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
holder.mLoadingImageView.setVisibility(View.VISIBLE);
}
});
和 holder
从 updatePalette
函数处理 that logic
(为卸载的图像获取不同的颜色),here its code or the whole demo 如果需要
在滑翔什么?
Glide.with(holder.mImageView.getContext())
.load(item.getUrl())
.into(/*WHAT*/);
任何重复都会有所帮助。
placeholder Image设置方法Picasso
和Glid
相同
滑行
Glide.with(holder.mImageView.getContext())
.load(item.getUrl())
.placeholder(R.drawable.placeholder)
.into(imageView)
毕加索
Picasso.with(holder.mImageView.getContext())
.load(item.getUrl())
.placeholder(R.drawable.placeholder)
.into(imageView)
您可以在 glide 中使用 Target or SimpleTarget (implements Target) 实现相同的效果。
即
Glide.load("http://somefakeurl.com/fakeImage.jpeg")
.asBitmap()
.fitCenter()
.into(new SimpleTarget(250, 250) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
// Image Loaded successfully.
}
@Override
public void onLoadStarted(Drawable placeholder){
// Image Loading starts
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable){
// Image Loading failed
}
});
}
使用 Picasso 的占位符功能保留 PlaceHolder 直到加载图像
Picasso.with(context)
.load("image_url")
.placeholder(R.drawable.ic_launcher)
.into(imageView);
最后我做到了
private ColorDrawable[] vibrantLightColorList =
{
new ColorDrawable(Color.parseColor("#9ACCCD")), new ColorDrawable(Color.parseColor("#8FD8A0")),
new ColorDrawable(Color.parseColor("#CBD890")), new ColorDrawable(Color.parseColor("#DACC8F")),
new ColorDrawable(Color.parseColor("#D9A790")), new ColorDrawable(Color.parseColor("#D18FD9")),
new ColorDrawable(Color.parseColor("#FF6772")), new ColorDrawable(Color.parseColor("#DDFB5C"))
};
然后
Glide.with(holder.mImageView.getContext())
.load(item.getUrl())
.placeholder(getRandomDrawbleColor())
.into(holder.mImageView);
和
public ColorDrawable getRandomDrawbleColor() {
int idx = new Random().nextInt(vibrantLightColorList.length);
return vibrantLightColorList[idx];
}