xaml - Xamarin 使用相对布局和背景图像形成页面布局
问题描述
我是 Xamarin 表单和 Xaml 的新手,尝试设计带有背景图像的页面布局,我发现使用相对布局,我可以使用 aspect 属性将图像扩展到整个屏幕。但是,当我在 RelativeLayout 中的图像之后放置网格或布局时,它不会扩展到整个区域,它只会覆盖给定的内容。
我试图使用相对布局来实现这一点。我正在使用带有 aspect 属性的 Image 标签,然后在图像顶部使用我的 stacklayout。
<RelativeLayout>
<Image Aspect="AspectFill" Source="c1.jpg" />
<StackLayout>
<Button Text="Meha" TextColor="White"/>
</StackLayout>
</RelativeLayout>
我希望按钮覆盖整个宽度并将其垂直居中对齐。
解决方案
这就是我通常解决这种情况的方法:
<Grid HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="White">
<Image Source="c1.jpg" Aspect="AspectFill" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="Center">
<Button Text="Meha" TextColor="Black" HorizontalOptions="FillAndExpand"/>
</StackLayout>
</Grid>
推荐阅读
- reactjs - react js项目的导航栏中没有正确显示品牌标志?
- java - 有没有办法从不同的方法访问数组?
- amazon-web-services - 有没有办法从 cloudwatch 检查 EBS 卷上剩余的磁盘空间?
- asp.net-mvc-4 - Asp.Net MVC 4 App - 在 iframe 清除 SQL Server 会话中发送请求
- python - 我们如何在 Python 中将接收到的数据转换为 JSON 格式
- excel - 在excel中为同一列中的值组创建平均值列
- python - 在python中实现PCA和k最近
- angular - 离子项目中 f5 后的不同设置
- php - 选择 pdo 找不到像 & ' 这样的符号
- list - Windows Batch - 从列表中选择名称