使用TransitionDrawable实现渐变效果(比使用AlphaAnimation效果要好,可避免出现闪烁问题)


private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    // Use TransitionDrawable to fade in.
    final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mContext.getResources(), bitmap) });
    //noinspection deprecation
        imageView.setBackgroundDrawable(imageView.getDrawable());
    imageView.setImageDrawable(td);
    td.startTransition(200);
}
相关标签

扫一扫

在手机上阅读