我有一個listview有三個不同的單元格內容,通過綁定檢查,只有一個顯示在單元格中。我沒有設置視圖單元格的高度,但將其堆棧佈局子項的垂直選項設置爲「填充」。現在,這可以在android上運行,但神祕的不是iOs。我已經將hasuneven行設置爲true,但是在點擊每個單元格時,我注意到高度是相同的。我將展示的XAML代碼和項目源代碼:Listview HasUnEvenRows不工作
<ListView
x:Name = "lvConversations"
VerticalOptions = "FillAndExpand"
HorizontalOptions = "FillAndExpand"
IsGroupingEnabled = "false"
SeparatorVisibility = "None"
HasUnevenRows = "true"
ItemSelected = "messageSelected"
BackgroundColor = "#F8F8F8"
>
<ListView.ItemTemplate>
<DataTemplate>
<local:ScaledViewCell>
<local:ScaledStackLayout
VerticalOptions = "Fill"
HorizontalOptions = "FillAndExpand"
Orientation = "Vertical"
Spacing = "0">
<local:ScaledStackLayout
VerticalOptions = "Fill"
HorizontalOptions = "FillAndExpand"
Orientation = "Vertical"
Spacing = "0"
IsVisible = "{Binding isGroupHeader, Converter = {StaticResource inverter}}"
BackgroundColor = "Transparent">
<!-- OUTGOING -->
<local:ScaledStackLayout
HorizontalOptions = "FillAndExpand" Orientation = "Horizontal"
IsVisible = "{Binding isOutgoing}">
<local:ScaledStackLayout
VerticalOptions = "Fill"
HorizontalOptions = "EndAndExpand"
BackgroundColor = "Transparent"
Orientation = "Vertical"
Margin = "21,14,15,0"
Spacing = "0">
<local:ScaledStackLayout
Orientation = "Horizontal"
VerticalOptions = "Fill"
HorizontalOptions = "EndAndExpand"
Spacing = "0"
>
<local:CorneredView
CornerRadius = "15"
BackgroundColor = "#d3eaf6"
VerticalOptions = "Fill"
HorizontalOptions = "End"
>
<Label
VerticalOptions = "Fill"
HorizontalOptions = "Fill"
Text = "{Binding message}"
FontSize = "10"
TextColor = "Black"
Margin = "7,10,7,10"
LineBreakMode = "WordWrap"
/>
</local:CorneredView>
<Image
Margin = "0,11,7,0"
Source = "ic_msg_arrow_outgoing"
WidthRequest = "5"
HeightRequest = "10"
Aspect = "AspectFit"
BackgroundColor = "Transparent"
VerticalOptions = "Start"
/>
<ffimageloading:CachedImage
WidthRequest = "37"
HeightRequest = "37"
BackgroundColor = "Transparent"
VerticalOptions = "Start"
Aspect = "AspectFill"
Source = "{Binding sender.imageUrl}"
DownsampleToViewSize = "true"
DownsampleUseDipUnits = "true"
>
<ffimageloading:CachedImage.Transformations>
<fftransformations:CircleTransformation>
<x:Arguments>
<x:Double>2</x:Double>
<x:String>#FF8A07</x:String>
</x:Arguments>
</fftransformations:CircleTransformation>
</ffimageloading:CachedImage.Transformations>
</ffimageloading:CachedImage>
</local:ScaledStackLayout>
<Label
Margin = "0,3,0,0"
VerticalOptions = "Center"
HorizontalOptions = "Start"
Text = "{Binding formattedDateSent}"
HeightRequest = "10"
FontSize = "8"
TextColor = "#4D212121"/>
</local:ScaledStackLayout>
</local:ScaledStackLayout>
<!--INCOMING-->
<local:ScaledStackLayout
WidthRequest = "284"
VerticalOptions = "Fill"
BackgroundColor = "Transparent"
Orientation = "Vertical"
Margin = "15,14,21,0"
Spacing = "0"
IsVisible = "{Binding isOutgoing, Converter = {StaticResource inverter}}">
<local:ScaledStackLayout
Orientation = "Horizontal"
WidthRequest = "284"
VerticalOptions = "Fill"
Spacing = "0"
>
<ffimageloading:CachedImage
WidthRequest = "37"
HeightRequest = "37"
BackgroundColor = "Transparent"
VerticalOptions = "Start"
Aspect = "AspectFill"
Source = "{Binding sender.imageUrl}"
DownsampleToViewSize = "true"
DownsampleUseDipUnits = "true"
>
<ffimageloading:CachedImage.Transformations>
<fftransformations:CircleTransformation>
<x:Arguments>
<x:Double>2</x:Double>
<x:String>#FF8A07</x:String>
</x:Arguments>
</fftransformations:CircleTransformation>
</ffimageloading:CachedImage.Transformations>
</ffimageloading:CachedImage>
<Image
Margin = "7,15,0,0"
Source = "ic_msg_arrow_incoming"
WidthRequest = "5"
HeightRequest = "10"
Aspect = "AspectFit"
BackgroundColor = "Transparent"
VerticalOptions = "Start"
/>
<local:CorneredView
WidthRequest = "235"
VerticalOptions = "Fill"
CornerRadius = "15"
BackgroundColor = "#ECECEC"
IsClippedToBounds = "true"
>
<Label
VerticalOptions = "Fill"
HorizontalOptions = "FillAndExpand"
Text = "{Binding message}"
FontSize = "10"
TextColor = "Black"
Margin = "7,10,7,10"
LineBreakMode = "WordWrap"
/>
</local:CorneredView>
</local:ScaledStackLayout>
<Label
Margin = "0,3,0,0"
VerticalOptions = "Center"
HorizontalOptions = "End"
Text = "{Binding formattedDateSent}"
HeightRequest = "10"
FontSize = "8"
TextColor = "#4D212121"/>
</local:ScaledStackLayout>
</local:ScaledStackLayout>
<!--Message Group-->
<local:ScaledStackLayout
Margin = "0"
Padding = "0"
Spacing = "0"
Orientation = "Vertical"
VerticalOptions = "Fill"
IsVisible = "{Binding isGroupHeader}"
BackgroundColor = "Transparent"
>
<!--label and button-->
<local:ScaledStackLayout
Margin = "9,0,9,0"
HeightRequest = "19"
Orientation = "Horizontal"
Padding = "0,5,7,0"
BackgroundColor = "Transparent">
<Label
Text = "{Binding groupHeaderTitle}"
HorizontalOptions = "FillAndExpand"
HeightRequest = "8"
FontSize = "8"
TextColor = "#212121"
VerticalTextAlignment = "Center"
HorizontalTextAlignment = "Center"
BackgroundColor = "Transparent"/>
</local:ScaledStackLayout>
<BoxView
Margin = "9,0,9,0"
HorizontalOptions = "FillAndExpand"
HeightRequest = "1"
BackgroundColor = "#4D212121"/>
</local:ScaledStackLayout>
</local:ScaledStackLayout>
</local:ScaledViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
正如你所看到的,細胞重疊。
我用來填充列表視圖中的代碼是這樣的:
public void OnSuccess(JObject response, BaseAPI caller)
{
if (Constants.isDebug)
{
JObject json = TestData.getTestData("conversation_messages_listed.json");
response = json;
}
ObservableCollection<Message> arrMessages = JsonConvert.DeserializeObject<ObservableCollection<Message>>(response["messages"].ToString(), new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore,
MissingMemberHandling = MissingMemberHandling.Ignore
});
lvConversations.ItemsSource = arrMessages;
}
請幫幫忙,我是新來xamarin。
很難說沒有ScaledStackLayout,ScaledViewCell和可能CorneredView的代碼,如果你想提供樣本來重現問題,它可能會加速解決方案。 –
這些只是Stacklayout,視單元和框架的簡單子類。除超類外沒有太多變化,只是它們根據設備屏幕尺寸縮放它們的大小。我在應用程序的其他頁面上使用它,所以我很確定它不在導致問題的那些頁面上。 – MetaSnarf
我需要編寫大量代碼來重現(消息類,轉義等)。如果您仍然需要幫助,請提供示例項目。 –