I want to create a ImageButton and set an image as background mantaining original size. So I use this few lines of code find on StackOverflow too:
ImageButton retry = new ImageButton(this); Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.button2); retry.setImageBitmap(image); retry.setMinimumWidth(image.getWidth()); retry.setMinimumHeight(image.getHeight()); But unfortunately I obtain following result:

Obviously I don't want the "background button", but only the image. How can I do?