私は次のコードを持っています:
<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>
私は通常、次のように画像にMargin
を設定します。
<Frame HeightRequest="100" WidthRequest="100" BackgroundColor="Purple" Padding="0" HasShadow="false">
<Image Margin="25" VerticalOptions="Center" Source="assets/avatar-man.png"></Image>
</Frame>
Frame
のサイズ(高さまたは幅)を取り、Image
のサイズを引き、2で割るだけです。これにより、画像サイズが50に設定されます。
フレームのサイズが変わらない場合にそれを行う簡単な方法。