Home > Software design >  Android. PaddingLeft or PaddingRight for button has no effect
Android. PaddingLeft or PaddingRight for button has no effect

Time:02-19

It's kind of duplicate question. But since no solution worked for me I would try again.

I have just a simple button in my layout.

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:paddingHorizontal="xyz"
        android:text="My button"/>

</LinearLayout>

And I want to add some horizontal padding for text within it.

However it has no effect.

Maybe you have an idea, what could be the reason for this issue?

CodePudding user response:

After two hours I found a solution and hope it will help someone else.

My naive approach was to use paddingHorizontal. But it doesn't work.

Also do not work paddingLeft and paddingRight.

But paddingStart and paddingEnd did the job

CodePudding user response:

Try using android:paddingHorizontal="72dp" if you want to give padding on both sides. Alternatively if you want to give padding on just a single side you can use android:paddingEnd="32dp" or android:paddingStart="32dp"

  • Related