Ich habe folgenden Code:
<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>
Aus irgendeinem Grund wird die Bildhöhenanforderung jedoch ignoriert und füllt den gesamten Bildschirm wie folgt aus:
Weiß jemand, warum dies ignoriert wird und wie dies behoben werden kann?
Ich hatte das gleiche Problem und endete mit einem StackLayout wie folgt um mein Bild:
<StackLayout>
<Image Source="{Binding MyImage}" WidthRequest="50" HeightRequest="50"/>
</StackLayout>
Normalerweise setze ich einfach eine Margin
auf das Bild, wie folgt:
<Frame HeightRequest="100" WidthRequest="100" BackgroundColor="Purple" Padding="0" HasShadow="false">
<Image Margin="25" VerticalOptions="Center" Source="assets/avatar-man.png"></Image>
</Frame>
Nehmen Sie einfach die Größe (Höhe oder Breite) von Frame
, subtrahieren Sie die Größe von Image
und dividieren Sie durch 2. Dadurch wird die Bildgröße auf 50 festgelegt.
Einfache Möglichkeit, wenn sich die Größe des Rahmens nicht ändert.