我有以下代码:

<ScrollView Orientation="Vertical" Padding="0" VerticalOptions="FillAndExpand">
                <StackLayout Spacing="0" Padding="15,0">
                    <Frame HasShadow="false" BackgroundColor="Transparent" Padding="0">
                        <RelativeLayout BackgroundColor="Olive" Padding="0" VerticalOptions="End">
                            <Frame HeightRequest="100" WidthRequest="100" BackgroundColor="Purple" Padding="0" HasShadow="false">
                                <Image HeightRequest="50" WidthRequest="50" Source="assets/avatar-man.png"></Image>
                            </Frame>
                            <BoxView HeightRequest="100" BackgroundColor="Teal" RelativeLayout.XConstraint="{ConstraintExpression Type=Constant, Constant=100}" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1, Constant=-100}" />
                            <Frame BackgroundColor="Transparent" HasShadow="false" Padding="0" RelativeLayout.XConstraint="{ConstraintExpression Type=Constant, Constant=100}" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1, Constant=-100}">
                                <Label>Hello</Label>
                            </Frame>
                        </RelativeLayout>
                    </Frame>
                </StackLayout>
            </ScrollView>

但是,由于某种原因,“图像高度”请求将被忽略,而不是显示50x50单位正方形,而是像这样填充整个屏幕:

有谁知道为什么这会被忽略以及如何解决?

最佳答案

我遇到了同样的问题,最终我在图像周围包裹了一个StackLayout,如下所示:

<StackLayout>
  <Image Source="{Binding MyImage}" WidthRequest="50" HeightRequest="50"/>
</StackLayout>

关于c# - Xamarin形式: Image height request ignored inside frame inside relative layout,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30427009/

10-10 14:43