[英]how to Fill Image fullscreen in stackLayout in Xamarin?
*如何在Xamarin的stackLayout中填充圖像全屏? 我無法將Image設置為適合stacklayout .XAML 文件代碼
<StackLayout Padding="0" BackgroundColor="Yellow">
<Image Source="ic_splash.png" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" > </Image>
</StackLayout>
</ContentPage>
最后我使用下面的代碼解決了問題....
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Your.Namespace.Views.LoginView"
Title="{Binding Title}"
BackgroundImage="BackgroundImage.png">
<StackLayout>
<!-- Your stuff goes here -->
</StackLayout>
</ContentPage>
我使用上面的代碼將背景圖像設置為適合屏幕....
BackgroundImage="BackgroundImage.png"
BackgroundImage屬性的問題是圖像比例可能會隨着屏幕尺寸的變化而變化。
在這里,我找到了如何使用RelativeLayout填充所有屏幕並保存比例:
<RelativeLayout>
<Image Source="Jupiter.png" Opacity="0.3"
RelativeLayout.WidthConstraint=
"{ConstraintExpression Type=RelativeToParent, Property=Width}"
RelativeLayout.HeightConstraint=
"{ConstraintExpression Type=RelativeToParent, Property=Height}"/>
<Grid RelativeLayout.WidthConstraint=
"{ConstraintExpression Type=RelativeToParent, Property=Width}"
RelativeLayout.HeightConstraint=
"{ConstraintExpression Type=RelativeToParent, Property=Height}">
<Label Text="Hello world from XAML"/>
</Grid>
</RelativeLayout>
因為你的android模擬器上沒有物理鍵。 通過使用具有物理鍵的模擬器將很好
或者使用您的第一個代碼,您可以將圖像屬性方面設置為AspectFill,這將最終裁剪您的圖像,同時保持縱橫比。
<StackLayout Padding="0" BackgroundColor="Yellow">
<Image Source="ic_splash.png" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Aspect="AspectFill" > </Image>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.