[英]listview scrolling issue in android 9.0 - xamarin.forms
I am trying to create a chat UI in my xamarin.forms app.I followed this tutorial Xamboy chat UI .The github link is Sample .我正在尝试在我的 xamarin.forms 应用程序中创建一个聊天 UI。我按照本教程Xamboy chat UI 进行操作。github链接是Sample 。
In this tutorial to acheive the chat UI,They rotated the ListView and ViewCells main layout to 180 degrees so that the list start from the bottom.在本教程中,为了实现聊天 UI,他们将 ListView 和 ViewCells 主布局旋转了 180 度,以便列表从底部开始。
Xaml xml
<Grid RowSpacing="0"
ColumnSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="1" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<controls:ExtendedListView Grid.Row="0"
ItemTemplate="{StaticResource MessageTemplateSelector}"
ItemsSource="{Binding Messages}"
Margin="0"
ItemTapped="OnListTapped"
Rotation="180"
FlowDirection="RightToLeft"
HasUnevenRows="True" x:Name="ChatList"
VerticalOptions="FillAndExpand"
SeparatorColor="Transparent"
ItemAppearingCommand="{Binding MessageAppearingCommand}"
ItemDisappearingCommand="{Binding MessageDisappearingCommand}">
</controls:ExtendedListView>
<BoxView HorizontalOptions="FillAndExpand"
HeightRequest="1"
BackgroundColor="#61427D"
Grid.Row="1"/>
<partials:ChatInputBarView Grid.Row="2"
Margin="0,0,0,0"
x:Name="chatInput"/>
</Grid>
This worked till android 8.0.这一直工作到android 8.0。 But in android 9.0, the chat scrolling is stuck and scroll in the wrong direction.
但是在android 9.0中,聊天滚动卡住并且滚动方向错误。 How can I solve this.
我该如何解决这个问题。 Is there any better solution for implementing chat UI in xamarin forms?
是否有更好的解决方案以 xamarin 形式实现聊天 UI? Any help is appreciated.
任何帮助表示赞赏。
Edit: I removed the rotation of listview and followed this repo.编辑:我删除了 listview 的旋转并关注了这个 repo。 Monkeychat Which worked fine.
Monkeychat效果很好。
This bug is reported in github xamrin.forms so go through it, it helps you https://github.com/xamarin/Xamarin.Forms/issues/7166 .这个错误在 github xamrin.forms 中报告,所以通过它,它可以帮助你https://github.com/xamarin/Xamarin.Forms/issues/7166 。
Workaround: credits mabdollahiasl解决方法:贷记 mabdollahiasl
Use CollectionView instead of ListView.使用 CollectionView 而不是 ListView。 Use custom renderer:
使用自定义渲染器:
[assembly: ExportRenderer(typeof(CollectionView), typeof(ExCollectionViewRenderer))]
namespace Healx.Droid.CustomRenderer
{
public class ExCollectionViewRenderer : CollectionViewRenderer
{
public ExCollectionViewRenderer(Context context) : base(context)
{
}
private int dy = 0;
public override void OnScrolled(int dx, int dy)
{
this.dy = dy;
base.OnScrolled(dx, dy);
}
public override bool Fling(int velocityX, int velocityY)
{
return base.Fling(velocityX, Math.Abs(velocityY) * Math.Sign(dy));
}
protected override void OnElementChanged(ElementChangedEventArgs<ItemsView> elementChangedEvent)
{
base.OnElementChanged(elementChangedEvent);
}
}
}
You can use the list in normal degrees and change the list orientation from c#.您可以以正常度数使用列表并从 c# 更改列表方向。
Try something like this:尝试这样的事情:
var list = your message list;
new ObservableCollection<Model of your list>(list.OrderByDescending(x =>
x.yourObjectDateTime).ToList());
I presume you use datetime in your Model, if u don't you'll need to implement this to properly order your list.我想你在你的模型中使用了日期时间,如果你不这样做,你需要实现它来正确排序你的列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.