【问题标题】:set background image to relative layout in xamarin.forms在 xamarin.forms 中将背景图像设置为相对布局
【发布时间】:2017-12-12 20:59:05
【问题描述】:

如何将背景图片设置为xamarin.forms可移植项目中的相对布局?

我已经尝试了以下代码:

Xamal 文件

 <RelativeLayout x:Name="Title">
    <Label Text="Hello Xamarin"
        TextColor="Black"
        FontSize="22"
        FontFamily="Tahoma"
        HorizontalOptions="Center"
        HorizontalTextAlignment="Center"
        RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width, Factor=0.03}"
        RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Factor=0, Property=Y}"
     />

xaml.cs 文件

public partial class MainApp : ContentPage
{

    public Image BGImage { get; set; }
    public MainApp()
    {
        this.BackgroundImage = "/Images/landing_page.jpg";
        BindingContext = this;
        InitializeComponent();
    }
}

【问题讨论】:

    标签: xamarin.forms


    【解决方案1】:

    您可以在相对布局中添加图像视图,请参阅以下链接;

    https://forums.xamarin.com/discussion/17794/image-as-background

    【讨论】:

      【解决方案2】:

      如果要在 Xamarin 项目中为整个页面在 XAML 文件中添加背景图像,请使用 BackgroundImage 属性。

      <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                   xmlns:local="clr-namespace:PhoneDailerDemo"
                   x:Class="PhoneDailerDemo.MainPage"
                   BackgroundImage="image3.jpg">
      
          <Label Text="Welcome to Xamarin Forms!" 
                 VerticalOptions="Center" 
                 HorizontalOptions="Center" />
          <StackLayout Padding="100">
             //..........
          </StackLayout>
      </ContentPage>
      

      【讨论】:

      • 这对我有用,但图像扭曲成比例。如何将图像设置为居中和填充?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-05
      • 2018-05-22
      • 2016-03-23
      • 2013-11-16
      • 1970-01-01
      • 2017-07-18
      • 1970-01-01
      相关资源
      最近更新 更多