How should I put my padded jacket when I put an image on the Android button?

Asked 2 years ago, Updated 2 years ago, 165 views

I add a button on Android I want to put the image in the center and put a schedule padding.

<Button
    android:background="@drawble/~"
    /> 

I did it like this and it was full. ㅜ<

<Button
    android:drawableTop="@drawable/~"
    /> 

This goes up and...TT

I wish I could be in the center! Masters, please tell us!

android button image padding

2022-09-22 21:43

2 Answers

If the parent layout is RelativeLayout

<ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:paddingStart="10dp"
        android:src="@drawable/image"
        android:background="@android:color/transparent" />

If the parent layout is LinearLayout or FrameLayout, then

<ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:paddingStart="10dp"
        android:src="@drawable/download"
        android:background="@android:color/transparent" />

I think we can do it like this.


2022-09-22 21:43

using and src imagebutton drawable want want the Set, padding scaletype and allocation of inserted into it.~

And if you care about the background, assign it to @null~


2022-09-22 21:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.