I am dynamically loading images to a image buttons on my screen. The images will not be known in advance and are diff size.
Does anyone know how to ensure the imagebutton size remains unaltered by whatever image is assigned to it. Preferably stretching the image to fit the button. I have tried using android:scaleType=”fitXY” and setting th ewidth and height to hard values (not preferable). No matter what i do the image dictates the size of the button not vice versa! Help!
I tried a combo of the following. the images come randomly from a search of internet.
<ImageButton
android:id="@+id/ImageButton1"
android:layout_height="93px"
android:src="@drawable/image1"
android:layout_width="93px"
android:background="93px" />
<ImageButton
android:id="@+id/ImageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image1"
android:scaleType="fitXY" />
Much appreciated of any help!
Instead of setting the size of each ImageButton, place the button in a container layout and set the size of the container. For example:
That should force your image button to be no bigger than the size of the container that it resides in.