I would like to understand how to positioning elements within a listview (CustomCell) as this will be my main display element. But I have difficulties to use the AbsoluteLayout tag, maybe anyone could give some hints.
I'am using VisualStudio 2017 15.9, test it on the Android emulator (but don't think this is relevant)
I have an example from the internet what is running and in priciple I understand it. I play around with all ways to positioning the elements as wanted, but with no success.
- For example I would like to have the both labels always in the middle (x=50%) of the row, regardless of the size of the image. The AbsoluteLayout does not work as expected, maybe because it inside a StackLayout.
The labels are always directly after the image with a little gap.
- Additionally I would like to positioning the second label in the Yposition, so there is no gap between the first and the second label.
Actually the first label starts on y=0 and the second label is at about y=50% and so there is a gap between them.
Thanks for help, Frank
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="FormsListViewSample.MainViewXaml"
xmlns:local="clr-namespace:FormsListViewSample;assembly=FormsListViewSample"
Title="ListView Xaml Sample"
>
<ContentPage.Content>
<ListView x:Name="lstView" RowHeight="50">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<AbsoluteLayout>
<StackLayout Orientation="Horizontal" >
<Image Source="{Binding Image}" BackgroundColor="Aqua" />
<StackLayout Orientation="Vertical" BackgroundColor="Yellow" >
<Label BackgroundColor="Red" Text = "{Binding Name}" AbsoluteLayout.LayoutBounds="0.5, 0, 100, 30" AbsoluteLayout.LayoutFlags="PositionProportional"/>
<Label BackgroundColor="Blue" Text = "{Binding Type}" AbsoluteLayout.LayoutBounds="0.5, 0.4, 100, 30" AbsoluteLayout.LayoutFlags="PositionProportional"/>
</StackLayout>
</StackLayout>
</AbsoluteLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
</ContentPage>