I use a table layout to layout buttons using weights, the buttons get 0dip size or wrap_content and so they expand by their weight.
I'm trying to convert a button to ImageButton and set the image to be in the button size and not expand it.
I let the button get created and get it's size and then I assign the image and limit it's height using ImageButton.setMaxHeight();
final ImageButton ib = (ImageButton) findViewById(R.id.buttonOptions);
ib.post(new Runnable() {
public void run() {
final int height = ib.getHeight();
ib.setScaleType(ScaleType.FIT_CENTER);
ib.setMaxHeight(5); // or height
ib.setImageResource(R.drawable.options);
}});
The images is being drawn in it's original size, thus expanding the button... setMaxHeight() is not limiting the image height/width. Any idea why?
solved it using
ib.setAdjustViewBounds(true);