Java tutorial
//package com.java2s; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.BitmapFactory.Options; import android.graphics.drawable.BitmapDrawable; import android.view.View; public class Main { @SuppressWarnings("deprecation") public static void setImageBackground(View view, int width, int height, int ResId, Activity context) { Options opts = new Options(); opts.outHeight = height; opts.outWidth = width; opts.inJustDecodeBounds = false; Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResId, opts); view.setBackgroundDrawable(new BitmapDrawable(bitmap)); } }