Android 毕加索将同一图像加载到多个图像时遇到的问题
因此,正如名字所说,我在将同一图像加载到多个ImageView时遇到问题, 我遇到的问题是,对于每个图像视图,我希望在每个视图上提供稍微不同的转换。然而,问题是只有第一个变换应用于两个图像 下面是毕加索部分的代码Android 毕加索将同一图像加载到多个图像时遇到的问题,android,android-imageview,picasso,Android,Android Imageview,Picasso,因此,正如名字所说,我在将同一图像加载到多个ImageView时遇到问题, 我遇到的问题是,对于每个图像视图,我希望在每个视图上提供稍微不同的转换。然而,问题是只有第一个变换应用于两个图像 下面是毕加索部分的代码 RequestCreator request; ImageView background = getTarget(); if (background != null) { if (file != null && file.exists(
RequestCreator request;
ImageView background = getTarget();
if (background != null) {
if (file != null && file.exists()) {
request = Picasso.with(background.getContext()).load(file);
} else {
request = Picasso.with(background.getContext()).load(R.drawable.stock_living_room);
}
if (mBlurType == BLUR_NORMAL) {
request.fit();
request.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE);
request.centerCrop();
request.transform(new BlurTransformation(background.getContext(), 20));
} else {
request.resize(128, 128);
request.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE);
request.transform(new BlurTransformation(background.getContext(), 10));
}
if(applyGradient)
request.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE);
request.transform(new LinearGradientTransformation(mGradient));
request.into(background);
}
我意识到我有三次记忆策略,我只是想看看它是否有效。我遇到的问题是最后一部分:if(applyGradient)
下面是我调用这个具有上述代码的类的代码
mBackgroundImageViewTwo = new ImageView(getActivity());
mBackgroundImageViewTwo.setVisibility(View.VISIBLE);
mBackgroundImageViewTwo.getHeight();
Shader Gradient = new LinearGradient(0, 0, 1, 1,
new int[]{
ContextCompat.getColor(getActivity(), R.color.hot00Overlay),
ContextCompat.getColor(getActivity(), R.color.hot90Overlay)
},
new float[]{0f, 1f},
Shader.TileMode.CLAMP);
mImageHelper2 = new HomeGradientImageHelper(Gradient);
mImageHelper2.setImageTarget(mBackgroundImageViewTwo, true);
mBackgroundImageView = new ImageView(getActivity());
mBackgroundImageView.getHeight();
Shader mGradient = new LinearGradient(0, 0, 1, 1,
new int[]{
ContextCompat.getColor(getActivity(), R.color.cool00Overlay),
ContextCompat.getColor(getActivity(), R.color.cool90Overlay)
},
new float[]{0f, 1f},
Shader.TileMode.CLAMP);
mImageHelper = new HomeGradientImageHelper(mGradient);
mImageHelper.setImageTarget(mBackgroundImageView, true);
有趣的是,这两个图像视图在相同的颜色下看起来完全相同,即使我一次只做一个,颜色也会大不相同
另一个有趣的地方是,如果毕加索的目标是通过使用view.findViewById(reference)找到的东西,那么调用FoundImageView.setVisibility(GONE)将不会产生任何效果
对此问题的任何想法都将不胜感激 确保在您的应用程序中放置一个适当的唯一密钥 毕加索使用该键在其
缓存中缓存位图。如果您的所有变换都有一个空键,那么毕加索认为您拥有相同的图像,并从缓存中返回图像。缓存的密钥基于url、资源id、转换密钥、位图解码选项等因素