xamarin.forms - xamarin 表单按钮文本换行到 2 行
问题描述
上面的代码工作正常,但对于下面的代码,按钮应该显示在单行中,但它会换行为 2 行。
<Frame CornerRadius="10" Grid.Row="1"
OutlineColor="#FF00BBEE" Margin="2,2"
Padding="0">
<StackLayout Padding="0">
<Grid Padding="0">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Label Grid.Row="0" TextColor="Black" FontSize="Large" Text=" B.Sc(Physician Assistant)" HorizontalOptions="Start" VerticalOptions="CenterAndExpand" FontAttributes="Bold"></Label>
<Label Grid.Row="1" TextColor="Black" FontSize="Medium" Text=" Duration:3 Years + 1 Year Internship" HorizontalOptions="Start" VerticalOptions="CenterAndExpand" FontAttributes="Italic"></Label>
<Label Grid.Row="2" TextColor="Black" FontSize="Medium" Text=" Eligibility: +2 Pass with Biology as one subject" HorizontalOptions="Start" VerticalOptions="CenterAndExpand"></Label>
<Grid Grid.Row="3">
<Button HorizontalOptions="Center" Text="Apply Now" VerticalOptions="CenterAndExpand"></Button>
</Grid>
</Grid>
</StackLayout>
</Frame>
解决方案
什么是上面的代码?根据您的代码,您的意思是Grid中有四个RowDefinitions,Label和Button应该具有相同的高度?
对于 Grid 的 RowDefinitions,RowDefinition.Height 属性的默认值为 *。所以每个 RowDefinition 都有相同的高度,但是你为每个 Label 和 Button 添加了VerticalOptions="CenterAndExpand",所以这个属性会改变高度以适应视图的内容。
如果我删除VerticalOptions="CenterAndExpand",您可以看到每个 RowDefinition 具有相同的高度。
<Frame
Margin="2.2"
Padding="0"
CornerRadius="10"
OutlineColor="#FF00BBEE">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Label
Grid.Row="0"
BackgroundColor="Red"
FontSize="Large"
Text=" B.Sc(Physician Assistant)"
TextColor="Black"
/>
<Label
Grid.Row="1"
BackgroundColor="Aquamarine"
Text=" Duration:3 Years + 1 Year Internship"
TextColor="Black"
/>
<Label
Grid.Row="2"
BackgroundColor="Beige"
Text=" Eligibility: +2 Pass with Biology as one subject"
TextColor="Black"
/>
<Button Grid.Row="3" Text="Apply Now" BackgroundColor="BlueViolet" />
</Grid>
</Frame>
推荐阅读
- javascript - 从 Google Analytics (analytics.js) 获取传输类型
- bash - 如何在环境变量中使用实际的正则表达式值?
- php - 来自 php 的 Microsoft Access,带有 odbc 错误:(07002)
- javascript - 如何粘贴交互interactjs拖动的元素
- c# - 无法通过 EWS 访问共享邮箱。401 在 C# 中未经授权
- express - Passport-twitter 策略需要刷新才能提供令牌
- c - 将随机生成的值从子进程发送到父进程
- mysql - MySQL JOIN 使用任一 NON-NULL 列来引用另一个表
- python - 如何从 Python 中的列表中隔离值?
- html - 如何在带有烧瓶的表单中的输入类型收音机中插入“已检查”