Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

xaml - How to align button text when increasing font size in settings

When creating a Button with text in Xamarin Forms and increasing the font size in the mobile settings, the text does not fit on the Button. Is there a way to adjust the size of the text to the Button?

Button code:

<Button
                        BackgroundColor="{StaticResource color1gray}"
                        BorderRadius="5"
                        HeightRequest="30"
                        Text="Cancelar"
                        WidthRequest="150" />
question from:https://stackoverflow.com/questions/65903048/how-to-align-button-text-when-increasing-font-size-in-settings

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It seems that height adjustment cannot be made automatically because you set " HeightRequest=50". You can easily resolve the problem with deleting HeightRequest=50 from your button.

enter image description here

It is better to use Grid to adjust the height according to the screensize. Example:

<Grid>
   <Grid.RowDefinitions>
      <RowDefinition Height="80*" />
      <RowDefinition Height="20*" />
   </Grid.RowDefinitions>
   <Grid Grid.Row="0">
   </Grid>

   <Button Grid.Row="1" BackgroundColor="{StaticResource color1gray}"
                        BorderRadius="5"
                        VerticalOptions="Center"
                        HorizontalOptions="Center"
                        Text="Cancelar" />
</Grid>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...