question

njsokalski avatar image
0 Votes"
njsokalski asked ·

Custom Button Text Alignment

I have a Button in Xamarin.Android, and I need to offset the text content from it's default position. My first thought was to use paddingTop & paddingBottom, but the Button seems to ignore them. Why is the Button ignoring paddingTop & paddingBottom, and how can I offset/position the text content of my Button? Thanks.

dotnet-android
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ColeXia-MSFT avatar image
0 Votes"
ColeXia-MSFT answered ·

Hello,

Welcome to Microsoft Q&A!

Test with the following simple code , it work fine .

<Button
        android:text="abc"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:paddingBottom="100dp"
        />


78686-capture.png


I suspect you set the same value on paddingTop & paddingBottom , in this cause the text position would not change .


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



capture.png (18.9 KiB)
· 8 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

That is clipping the text, not shifting it. I did not set the top & bottom.

0 Votes 0 ·

That is clipping the text, not shifting it

Sorry I can't get it , did you see the screen shot I post ?

0 Votes 0 ·

I may have found the problem (but not the solution). I am using a large textSize, which is causing the height of the actual text to be larger than the height of the Button. I expect that, because much of that space is not visible (just like a . or ,). However, I need the large textSize in order to make the text the appropriate width. I think the fact that the text ends up with a height larger than the Button is messing up the renderer.

0 Votes 0 ·
Show more comments

I agree that your screenshot is what I want, but mine is unfortunately not having the same effect.

0 Votes 0 ·