【发布时间】:2016-03-14 20:29:09
【问题描述】:
我正在使用 palette-v7:23.2.1 和 glide:3.7.0,如下所述,但有时是 dark 鲜艳的颜色没有成功提取,我得到了默认颜色。
在我清除滑翔的缓存并再次尝试使用相同的图像后,我得到了正确的颜色。奇怪的是,总是能提取出明亮的鲜艳颜色,但不会提取深色。
可能是什么问题以及如何解决?
在 onCreateView() 中:
Glide.with(mContext)
.load(artworkUrl)
.asBitmap()
.into(new BitmapImageViewTarget(mArtworkInToolbar) {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
new Palette.Builder(bitmap).generate(paletteAsyncListener);
super.onResourceReady(bitmap, anim);
}
});
听众:
public final Palette.PaletteAsyncListener paletteAsyncListener =
new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
if (palette == null) return;
int default = ContextCompat.getColor(mContext, R.color.colorPrimary);
int color = palette.getVibrantColor(default); //always ok
int colorDark = palette.getDarkVibrantColor(default); //not always
// --- Setting the color --
}
};
【问题讨论】:
-
github.com/bumptech/glide/wiki/…这个链接给出了这个问题的原因和解决方案
-
不推荐我使用的第一个解决方案,因为第二个异步调用可能会更新错误的 ViewHolder,但这不是我的情况。我也试过第二个例子,但有时它不会提取第二种颜色,或者在相同的场景和相同的图像中提取第一种颜色。
标签: android palette android-glide