I have a number of Button
s that are dynamically added to a GridView
using an Adapter
. These currently fit inside the GridView correctly, but...
I would like to add an image inside each button. I have banana.jpg
stored in my drawable
folder and I use the following code to set it inside the button:
button.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.banana));
However, I have two problems:
- The buttons seem to stretch to the size of the image.
- The image doesn't actually appear.
Is there some way to add an image to a button such that the current size of the button will scale the image down so that it fits? (Or, is it possible to calculate the size I will need the image to be so I can resize it manually?)