Android 'Image + Text' button

Asked 2 years ago, Updated 2 years ago, 23 views

I want to make this type of button on Android. I tried to use drwableTop, but drwableTop doesn't seem to be able to adjust the size of the image.

Is there a way to use the drawable top and adjust the image size? Or is it better to make the text into an image and make it into an image button?

Please advise me how to make it...

android

2022-09-21 17:32

2 Answers

You cannot change the image size of drawableTop in Xml. However, you can change the size of the drawable using the drawable.setBounds() function in Java code. Please refer to the link below for the detailed code.

If there are many use cases like this in the app, I think it would be a good idea to configure the layout by placing ImageView and TextView vertically using LinearLayout (or FrameLayout, RelativeLayout).


2022-09-21 17:32

As mentioned above, it is also recommended to use Linear Layout to arrange ImageView and TextView vertically.

In this case, the entire Linear Layout becomes a single button, so you can put on ClickListener on Linear Layout.

However, if it is used repeatedly, I think it would be better to make that configuration itself a custom widget.

I'm sure there's a code for similar features if you look it up.


2022-09-21 17:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.