Android examples for User Interface:ImageView
load Bitmap Into ImageView
//package com.java2s; import android.content.Context; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.TransitionDrawable; import android.widget.ImageView; public class Main { public static void loadBitmapIntoView(Context context, ImageView view, Bitmap bm, boolean fadeIn) { final Drawable previousDrawable = view.getDrawable(); if (fadeIn && previousDrawable != null) { final Drawable[] layers = new Drawable[2]; // Prevent cascade of TransitionDrawables. if (previousDrawable instanceof TransitionDrawable) { final TransitionDrawable previousTransitionDrawable = (TransitionDrawable) previousDrawable; layers[0] = previousTransitionDrawable .getDrawable(previousTransitionDrawable .getNumberOfLayers() - 1); } else { layers[0] = previousDrawable; }/*from ww w . j a va 2 s . c o m*/ layers[1] = new BitmapDrawable(context.getResources(), bm); TransitionDrawable drawable = new TransitionDrawable(layers); view.setImageDrawable(drawable); drawable.setCrossFadeEnabled(true); drawable.startTransition(200); } else { view.setImageBitmap(bm); } } }