Java tutorial
//package com.java2s; import android.content.Context; import android.content.res.Resources; import android.graphics.drawable.Drawable; public class Main { /** * Get the {@link Drawable} identified by {@code drawableId} and set its bounds * with the dimensions identified by {@code widthDimenId} and {@code heightDimenId}. * @param ctx Context * @param drawableId Identifier of the drawable. * @param widthDimenId Identifier of the resource to use as the width. * @param heightDimenId Identifier of the resource to use as the height. * @return The {@link Drawable} identified by {@code drawableId} bounded to {@code widthDimenId} and {@code heightDimenId}. */ public static Drawable boundedDrawable(Context ctx, int drawableId, int widthDimenId, int heightDimenId) { Drawable retVal; Resources res = ctx.getResources(); retVal = res.getDrawable(drawableId); retVal.setBounds(0, 0, res.getDimensionPixelSize(widthDimenId), res.getDimensionPixelSize(heightDimenId)); return retVal; } }