xaml - Xamarin xaml 试图在框架中获取彼此下方的文本标签
问题描述
我试图在一个框架中将文本标签放在彼此下方,但文本的行为真的很奇怪,而且我尝试过的没有任何效果。
我正在使用这段代码:
<AbsoluteLayout>
<Frame HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" TranslationY="285" TranslationX="10" HeightRequest="70" WidthRequest="120">
<StackLayout Orientation="Horizontal" Padding="0" Spacing="-10" HorizontalOptions="FillAndExpand" BackgroundColor="green">
<Image Source="mark_red.png" Scale="0.5" TranslationX="-20" TranslationY="-25"/>
<Label Text="Voeding" FontSize="20" TranslationX="-20"/>
<Label Text="Test" FontSize="20" TranslationY="-40"/>
</StackLayout>
</Frame>
<Frame HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" TranslationY="415" TranslationX="10" HeightRequest="70" WidthRequest="120" >
<StackLayout Orientation="Horizontal" Padding="0" Spacing="5" HorizontalOptions="FillAndExpand">
<Image Source="mark_green.png" Scale="0.5" TranslationX="-20" TranslationY="-25"/>
<Label Text="Sport" FontSize="20" TranslationX="-35"/>
</StackLayout>
</Frame>
<Frame HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" TranslationY="285" TranslationX="190" HeightRequest="70" WidthRequest="120">
<StackLayout Orientation="Horizontal" Padding="0" Spacing="5" HorizontalOptions="FillAndExpand">
<Image Source="mark_blue.png" Scale="0.5" TranslationX="-20" TranslationY="-25"/>
<Label Text="Slaap" FontSize="20" TranslationX="-35"/>
</StackLayout>
</Frame>
<Frame HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" TranslationY="415" TranslationX="190" HeightRequest="70" WidthRequest="120">
<StackLayout Orientation="Horizontal" Padding="0" Spacing="-45" HorizontalOptions="FillAndExpand">
<Image Source="mark_orange.png" Scale="0.5" TranslationX="-20" TranslationY="-25"/>
<Label Text="Huidige tijd" FontSize="20" TranslationX="15"/>
</StackLayout>
</Frame>
</AbsoluteLayout>
输出
我希望文本“测试”显示在文本“Voeding”下方的框架中。我将背景设为绿色以查看框的高度和宽度。我该怎么做?
解决方案
您需要将每个帧包装在另一个堆栈布局中以获得另一行。还摆脱了一些翻译。我非常谨慎地使用这些。它们不会很好地转换为不同的屏幕尺寸。
<Frame HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" TranslationY="285" TranslationX="10" HeightRequest="70" WidthRequest="120">
<StackLayout VerticalOptions="FillAndExpand">
<StackLayout Orientation="Horizontal" Padding="0" HorizontalOptions="FillAndExpand" BackgroundColor="Green">
<Image Source="mark_red.png" Scale="0.5" TranslationX="-20" TranslationY="-25"/>
<Label Text="Voeding" FontSize="20"/>
</StackLayout>
<Label Text="Test" FontSize="20" />
</StackLayout>
</Frame>
如果我对此进行编码,我将从具有两行和两列的网格开始,然后将堆栈布局放在正确的网格单元内。
<Grid Margin="20" ColumnSpacing="10" RowSpacing="10">
<Grid.RowDefinitions>
<RowDefinition Height="120"/>
<RowDefinition Height="120"/>
</Grid.RowDefinitions>
<StackLayout Grid.Column="0" Grid.Row="0" Padding="10" BackgroundColor="White">
<StackLayout Orientation="Horizontal">
<BoxView HeightRequest="20" WidthRequest="10" BackgroundColor="Red"/>
<Label Text="Voeding" FontSize="20"/>
</StackLayout>
<Label Text="Test" FontSize="20" />
</StackLayout>
<StackLayout Grid.Column="1" Grid.Row="0" Padding="10" BackgroundColor="White">
<StackLayout Orientation="Horizontal">
<BoxView HeightRequest="20" WidthRequest="10" BackgroundColor="Green"/>
<Label Text="Sport" FontSize="20" />
</StackLayout>
</StackLayout>
<StackLayout Grid.Column="0" Grid.Row="1" Padding="10" BackgroundColor="White">
<StackLayout Orientation="Horizontal">
<BoxView HeightRequest="20" WidthRequest="10" BackgroundColor="Blue"/>
<Label Text="Slaap" FontSize="20" />
</StackLayout>
</StackLayout>
<StackLayout Grid.Column="1" Grid.Row="1" Padding="10" BackgroundColor="White">
<StackLayout Orientation="Horizontal">
<BoxView HeightRequest="20" WidthRequest="10" BackgroundColor="Orange"/>
<Label Text="Huidige tijd" FontSize="20" />
</StackLayout>
</StackLayout>
</Grid>
因为我没有它们,所以我用盒子替换了你的图像。
推荐阅读
- laravel - laravel livewire 挂载动态字段
- java - 如何在 Visual Studio Code 中将 SpringBoot 应用程序作为独立的可执行 jar 构建和运行?
- javascript - 想为我的网站使用页面加载器
- reactjs - 更新到 React 17 时枚举出错,
- javascript - 格式化 mailto 链接,以便 PHP 可以清晰地解释它
- sql-server - 如何将证书和签名程序集部署到其他数据库?
- javascript - 反应JS | 无法将 undefined 或 null 转换为对象(带 Formik)
- javascript - 由于错误而无法加载模型并且 AppRegistry.registerComponent 未被调用 REACT-NATIVE
- flutter - 如何在颤动中保存范围滑块值
- java - 在 ORMlite 中获取磁盘上的 PostgreSql 表大小(字节)