图像不会在嵌套布局

时间:2017-07-14 21:56:24

标签: xamarin xamarin.forms

我在Xamarin Forms中的Grid内部有一个相对布局。相对布局中有一个图像。该图像具有AspectFill。

Xamarin.Forms.Aspect.AspectFill Field说:

  

缩放图像以填充视图。某些部分可能会被剪裁以填充视图。

图像仍未水平填充。如何解决它。

XAML

 <Grid x:Name="controlGrid" ColumnSpacing="0" Padding="0">
    <Grid.RowDefinitions>
        <RowDefinition Height="2*" />
        <RowDefinition Height="2*" />
        <RowDefinition Height="8*" />
        <RowDefinition Height="1*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>


    <!--Row 1-->
    <BoxView Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" BackgroundColor="Red" HeightRequest="1" VerticalOptions="End" HorizontalOptions="FillAndExpand" Margin="0" />
    <BoxView Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" BackgroundColor="Red" HeightRequest="1" VerticalOptions="Start" HorizontalOptions="FillAndExpand" Margin="0"/>
    <BoxView Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" BackgroundColor="Red" WidthRequest="1" VerticalOptions="FillAndExpand" HorizontalOptions="End" Margin="0"/>
    <BoxView Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" BackgroundColor="Red" WidthRequest="1" VerticalOptions="FillAndExpand" HorizontalOptions="Start" Margin="0"/>

    <RelativeLayout Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" >
        <Image Source="abstracttrianglex.png" Aspect="AspectFill" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="Red"/>
    </RelativeLayout>

    <!--Row 2-->
    <RelativeLayout Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" BackgroundColor="Teal" >
        <Image Source="abstracttrianglex.png"  Aspect="AspectFill" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="Blue"/>
    </RelativeLayout>

</Grid>

enter image description here

2 个答案:

答案 0 :(得分:1)

您必须为内部相对布局

提供XConstraint和YConstraint

以下链接

https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/relative-layout/

答案 1 :(得分:1)

以下工作

带约束的相对布局

lazy_static!{
    static ref DOWNLOADER : Mutex<downloader::Downloader> = 
Mutex::new(downloader::Downloader::new());
}
let (sender, receiver) = mpsc::channel();
DOWNLOADER.lock().unwrap().download(payload, sender);