Maurice's answer didnβt quite work for me, since I often get 0 back, which results in an Exception when trying to create a scaled bitmap:
IllegalArgumentException: width and height must be> 0
I found several other options if this helps someone else.
Option 1
imageButton is a View , which means we can get LayoutParams and use the built-in height and width properties. I found this from this other SO answer .
imageButton.getLayoutParams().width; imageButton.getLayoutParams().height;
Option 2
Our imageButton has a class that extends imageButton and then overrides the View # onSizeChanged .
Option 3
Get the drawing rectangle in the view and use the width() and height() methods to get the dimensions:
android.graphics.Rect r = new android.graphics.Rect(); imageButton.getDrawingRect(r); int rectW = r.width(); int rectH = r.height();
Combination
My final code completed combining the three and selecting max. I do this because I get different results, depending on what stage the application is at (for example, when the view has not been completely drawn).
int targetW = imageButton.getDrawable().getBounds().width(); int targetH = imageButton.getDrawable().getBounds().height(); Log.d(TAG, "Calculated the Drawable ImageButton height and width to be: "+targetH+", "+targetW); int layoutW = imageButton.getLayoutParams().width; int layoutH = imageButton.getLayoutParams().height; Log.e(TAG, "Calculated the ImageButton layout height and width to be: "+targetH+", "+targetW); targetW = Math.max(targetW, layoutW); targetH = Math.max(targetW, layoutH); android.graphics.Rect r = new android.graphics.Rect(); imageButton.getDrawingRect(r); int rectW = r.width(); int rectH = r.height(); Log.d(TAG, "Calculated the ImageButton getDrawingRect to be: "+rectW+", "+rectH); targetW = Math.max(targetW, rectW); targetH = Math.max(targetH, rectH); Log.d(TAG, "Requesting a scaled Bitmap of height and width: "+targetH+", "+targetW); Bitmap scaledBmp = Bitmap.createScaledBitmap(bitmap, targetW, targetH, true);