web-dev-qa-db-ja.com

Xamarinフォーム:相対レイアウト内のフレーム内で画像の高さの要求が無視されました

私は次のコードを持っています:

<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単位の正方形を表示する代わりに、次のように画面全体に表示されます。

Issue Image

これが無視される理由とこれを修正する方法を誰かが知っていますか?

8
sgarcia.dev

私は同じ問題を抱えていました、私は次のように私の画像の周りにStackLayoutをラップすることになりました:

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

私は通常、次のように画像に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に設定されます。

フレームのサイズが変わらない場合にそれを行う簡単な方法。

1
cfly24