Code example for ImageView

Methods: setImageBitmapsetScaleType, setBackgroundResource, setLayoutParams

0
    public View getView(int position, View convertView, ViewGroup parent) {
    	 
        ImageView imageView;
         
        if (convertView == null) {  
            imageView = new ImageView(mContext);
            /* 
            // Grid 
            imageView.setLayoutParams(new GridView.LayoutParams(THUMB_DIM,THUMB_DIM)); 
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); 
            //imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); 
            imageView.setPadding(4, 4, 4, 4); 
            */ 
            // Gallery 
            imageView.setLayoutParams(new Gallery.LayoutParams(unfocusedSize, unfocusedSize));
           //imageView.setLayoutParams(new Gallery.LayoutParams(200, 150)); 
            //imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); 
            imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
            imageView.setBackgroundResource(mGalleryItemBackground);
             
        } else { 
            imageView = (ImageView) convertView;
        } 
 
         
        String p = filepaths.get(position);
         
 
		BitmapFactory.Options options = new BitmapFactory.Options();
		//options.inSampleSize = 8; 
		options.inSampleSize = 4;
 
		 
		Bitmap bitMap;
		bitMap = BitmapFactory.decodeFile(p, options);
		//bitMap = BitmapFactory.decodeFile(u.getPath(), options); 
        imageView.setImageBitmap(bitMap);
		 
         
        return imageView;
    }