Xamarin.Forms 관련 레이아웃에 문제가 있습니다. 네 가지보기가 있습니다. 3 개의 이미지와 하나의 라벨이 사진으로 첨부됩니다. 제 3의 이미지가 필요합니다. 두 번째 이미지 아래 및 두 번째 이미지의 세로 크기가 image2에 대한 레이블의 크기에 따라 변경됩니다. 어떻게 Y를 image3에서 찾을 수 있습니까? XAML 위의 댓글에서 언급 한 바와 같이Xaml의 상대 레이아웃이 올바른 위치에보기를 입력 할 수 없습니다.
enter code here
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="demo.AttnamePage"
xmlns:local="clr-namespace:demo.MarkupExtensions" >
<ListView x:Name="AttNamea" HasUnevenRows="True" ItemSelected="AttNamea_ItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<RelativeLayout>
<Image x:Name="Mimage" Source="{Binding image }" Aspect="Fill"
RelativeLayout.WidthConstraint=
"{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=1}"
RelativeLayout.XConstraint=
"{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=0}"
RelativeLayout.YConstraint=
"{ConstraintExpression Type=RelativeToParent,Property=Height,Factor=0}"/>
<Image Source="{local:Embeddedimage ResourceId=Demo.Images.barM.jpg }" Aspect="Fill"
RelativeLayout.WidthConstraint=
"{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=1}"
RelativeLayout.YConstraint=
"{ConstraintExpression Type=RelativeToView,ElementName=Mimage,Property=Height,Factor=1}"
RelativeLayout.HeightConstraint=
"{ConstraintExpression Type=RelativeToView,ElementName=label1,Property=Height,Factor=1}"/>
<Label x:Name="label1" Text="{Binding attractionName}" TextColor="White" FontSize="16" HorizontalOptions="Center"
verticalOptions="Center"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=1}"
RelativeLayout.YConstraint=
"{ConstraintExpression Type=RelativeToView,ElementName=Mimage,Property=Height,Factor=1}"/>
<Image Source="{local:Embeddedimage ResourceId= demo.Images.barD.jpg }" Aspect="Fill"
RelativeLayout.WidthConstraint=
"{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=1}"
RelativeLayout.YConstraint=
"{ConstraintExpression Type=RelativeToView,ElementName=label1,Property=Y,Constant=40}"/>
</RelativeLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage>
왜 RelativeLayout을 사용하고 있습니까? 지금까지 설명한 것으로부터 Grid (단일 열 포함) 또는 Vertical StackLayout이 원하는 것을 처리합니다. 그러나 RelativeLayout을 사용하려면 C#의 유연성이 XAML보다 커서 C#의 마지막 이미지에 대한 제약 조건을 정의해야 할 수 있습니다. – DavidS
답장을 보내 주셔서 감사합니다. 이미지 위에 레이블을 붙이고 싶기 때문에 C#을 사용하려고합니다. 그렇습니다. 코드를 재생해야하지만 볼 수는 있습니다. –