Create an image view, given a drawable. you can set the max size of this imageview as well. : ImageView « UI « Android






Create an image view, given a drawable. you can set the max size of this imageview as well.

  
//package com.retain;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.util.Date;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.widget.ImageView;
import android.widget.Toast;

/**
 * @author Nazmul Idris
 * @version 1.0
 * @since Jul 8, 2008, 2:35:39 PM
 */
class AppUtils {

  /**
   * 127.0.0.1 in the emulator points back to itself. Use this if you want to
   * access your host OS
   */
  public static String EmulatorLocalhost = "10.0.2.2";

  /**
   * create an image view, given a drawable. you can set the max size of this
   * imageview as well.
   * 
   * @param iconWidth
   *            -1 means dont set this
   * @param iconHeight
   *            -1 means dont set this
   * @param imageRes
   *            -1 means dont set this
   */
  public static ImageView createImageView(Context activity, int iconWidth,
      int iconHeight, int imageRes) {
    ImageView icon = new ImageView(activity);
    icon.setAdjustViewBounds(true);
    icon.setScaleType(ImageView.ScaleType.FIT_CENTER);

    if (iconHeight != -1)
      icon.setMaxHeight(iconHeight);
    if (iconWidth != -1)
      icon.setMaxWidth(iconWidth);

    if (imageRes != -1)
      icon.setImageResource(imageRes);
    return icon;
  }

}// end class AppUtils

   
    
  








Related examples in the same category

1.Set ImageView width, height
2.extends ImageView
3.Load image with ImageView
4.Using ImageView within ListActivity
5.Using ImageView to display image and reference Image resource in layout xml file
6.ImageView background
7.Set Layout Parameters, Scale Type, background for ImageView
8.Using ImageView to display Image
9.ImageView click listener
10.Set Image resource for ImageView
11.Set Image Bitmap for ImageView
12.Set image Uri for ImageView
13.Adding Touch Listener to ImageView
14.Demonstrates setting size constraints on android.widget.ImageView
15.Create ImageView
16.download images from the Internet and binds those with the provided ImageView.
17.Choose a Picture