1
アンドロイドプラットフォームでイメージビューの幅を取得しようとしています。幅は "-1"です。私はOnAppearing()メソッドでこれを試しました。 iOSプラットフォームで正常に動作しています。助けのためのXamarinフォーム - Android - イメージビューの幅または高さを取得できません
C#の
protected override void OnAppearing()
{
base.OnAppearing();
myWidth = imagePusher.Width; //Width = -1 at android
}
XAML
...
<ScrollView x:Name="scrollPusher" Orientation="Horizontal" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}" RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}">
<RelativeLayout x:Name="rlPusher">
<StackLayout x:Name="stackPusher" Orientation="Horizontal" Spacing="0">
<Image x:Name="imagePusherSpacer" Source="pusherSpacer.jpg" Aspect="AspectFit">
</Image>
<Image x:Name="imagePusher" Source="pusher.jpg" Aspect="AspectFit">
</Image>
</StackLayout>
</RelativeLayout>
</ScrollView>
...
感謝。あなたはSizeChanged
イベント(hereを参照)
private void Image_OnSizeChanged(object sender, EventArgs e)
{
// image size should be set here
}
かOnSizeAllocated
を上書き(hereを参照)
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height); //must be called
if (this.width != width || this.height != height)
{
this.width = width;
this.height = height;
// do what ever you like here
}
}
サイズを購読することができますいずれか
ありがとうございますが、OnSizeAllocatedでは、送信者が指定されていないため、私が探しているビューはいつどのようにわかりますか? – anguish
または、istの読み込みが完了したかどうかをチェックするためだけにOnSizeAllocatedですか? – anguish
'OnSizeAllocated'を' View'や 'Page'でオーバーライドします。イメージのサイズが変更されているかどうかを手動で確認する必要があります。送信者はありません。 –