【发布时间】:2017-07-12 19:22:18
【问题描述】:
在 Xamarin 表单中仍然是新的我正在尝试添加图像。
我打开了一个新的 PCL 项目,有一个登录表单和一个主页。
我想将 2 张图片添加到主页,但其中一张图片会导致项目崩溃并调用未处理的异常。
在项目中。并将其添加到 Android 项目的 drawable libery 中。
希望能得到帮助,谢谢。
将我的 XAML 附加到名为 tmpImage 的第二个图像正在解决问题:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ComplexInstruction"
x:Class="ComplexInstruction.MainPage">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0,1*"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
<RowDefinition Height="0.1*"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
<RowDefinition Height="0.1*"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
<RowDefinition Height="0.1*"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
<RowDefinition Height="0.1*"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
<RowDefinition Height="0.1*"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
<RowDefinition Height="0.1*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.1*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="0.1*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="0.1*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Image Aspect="Fill" Source="logo_ComplexInstructions.jpg"
RelativeLayout.WidthConstraint=
"{ConstraintExpression Type=RelativeToParent, Property=Width}"
RelativeLayout.HeightConstraint=
"{ConstraintExpression Type=RelativeToParent, Property=Height}" Opacity="0.3" Grid.ColumnSpan="5" Grid.Row="0" Grid.RowSpan="2" />
<Image x:Name="tmpImage" Aspect="Fill" Source="SHA_6620.jpg"
RelativeLayout.WidthConstraint=
"{ConstraintExpression Type=RelativeToParent, Property=Width}"
RelativeLayout.HeightConstraint=
"{ConstraintExpression Type=RelativeToParent, Property=Height}"
Grid.ColumnSpan="5" Grid.Row="3" Grid.RowSpan="8" />
</Grid>
</ContentPage>
【问题讨论】:
-
图片的尺寸(宽度和高度,以像素为单位)是多少?
-
确切的例外是什么?
-
构建操作是否设置为
AndroidResource? -
相对布局在哪里使用?我看到您使用的是 RelativeLayout 高度和宽度约束,但我在您的标记中没有看到
<RealtiveLayout>
标签: c# xamarin xamarin.forms