1

I have a set of Buttons (not ImageButtons) declared in xml. They contain a background image. I want to be able to dictate the width of the Button via xml, via the use of weight... but I want to let the height to be dictated by the aspect ratio of the image.

I saw a similar question here, to which the answer involved the addition of android:adjustViewBounds="true" but the question concerned ImageViews rather than Buttons and when I tried the same additions to my Button code, it didn't appear to work.

Can what I want be achieved?

Community
  • 1
  • 1
Mick
  • 8,284
  • 22
  • 81
  • 173

1 Answers1

-2

You can use:

android:scaleType="fitXY" 

in layout of your Button or ImageButton (It's better if you use ImageButton).

Flavio Capaccio
  • 706
  • 4
  • 15
  • I wanted to use a Button rather than an ImageButton because I wanted to have some text (a number) on it. I know I could have the number included on the image but the number could be anything from 1 to 40, - that's a lot of images. – Mick Jul 19 '13 at 15:01
  • scaleType is a property of ImageButton but not of Button. – arlomedia May 03 '18 at 22:22