Reputation: 3108
I am attempting to create buttons with text and a drawableTop. I want the drawableTop to be the regular size of the stored image since I have different sizes for different screen sizes. Setting height and width to match_parent seems to be based on the text, and setting them to dip values changes the size of the button, but not the image. I tried scaleX and scaleY, but that changes the size of the text as well, which I don't want.
I am using the following, but the image appears much smaller than what it is saved as
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label"
android:drawableTop="@drawable/my_image" />
Is there anyway of creating a button with an image that automatically sets to it's full size?
Upvotes: 2
Views: 7468
Reputation: 865
In doc TextView#setCompoundDrawablesWithIntrinsicBounds, it says:
The Drawables' bounds will be set to their intrinsic bounds.
But, the reason the button isn't set the drawable to it's full size, is that we put the image to wrong res/drawable folder in app project. You may try to put the image to other drawable folder, such as drawable-xhdpi, drawable-hdpi, etc. The image will show in different size. Please check out this doc Supporting Multiple Screens.
Upvotes: 1
Reputation: 651
You can use a normal ImageView and set an onClickListener or XML onClick property for it.
If you want different states (e.g. pressed and unpressed) for it you can use a drawable defined in xml to set those.
Upvotes: 2