如何将 FadeInBitmapDisplayer 和 RoundedBitmapDisplayer 添加到我的图像中?
也有这个问题。我使用了 NOSTRA 的好建议,这是我的自定义课程:
public class FadeInRoundedBitmapDisplayer extends RoundedBitmapDisplayer {
int durationMillis;
String noRoundedCornersTag;
public FadeInRoundedBitmapDisplayer(int durationMillis, int roundPixels,
String noRoundedCornersTag) {
super(roundPixels);
this.durationMillis = durationMillis;
this.noRoundedCornersTag = noRoundedCornersTag;
}
@Override
public Bitmap display(Bitmap bitmap, ImageView imageView,
LoadedFrom loadedFrom) {
imageView.setImageBitmap((imageView.getTag() != null && imageView
.getTag().equals(noRoundedCornersTag)) ? bitmap : super
.display(bitmap, imageView, loadedFrom));
animate(imageView, durationMillis);
return bitmap;
}
public static void animate(ImageView imageView, int durationMillis) {
AlphaAnimation fadeImage = new AlphaAnimation(0, 1);
fadeImage.setDuration(durationMillis);
fadeImage.setInterpolator(new DecelerateInterpolator());
imageView.startAnimation(fadeImage);
}
}
您可以将 a 传递String noRoundedCornersTag
给构造函数。这使您可以imageView
在 XML 布局中指定单个 s 标记以跳过圆角半径过程(适用于背景图像等),例如:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="@string/no_rounded_corners_tag" />
构造函数调用如下所示:
new FadeInRoundedBitmapDisplayer(Constants.IMAGE_FADING_TIME,
getResources().getDimension(R.dimen.image_corner_radius),
getResources().getString(R.string.no_rounded_corners_tag))