简体   繁体   English

列表视图,如Xamarin形式的老虎机

[英]List view like Slot machine in Xamarin forms

I have 5 list view on the page. 我在页面上有5个列表视图。 Every list view has some list of texts. 每个列表视图都有一些文本列表。 Users scroll them to choice one. 用户滚动它们以选择一个。

The problem is: How can I detect that an item is centered the list view to select it as the selected item, like a slot machine. 问题是: 我如何检测某项位于列表视图的中心,以将其选择为选定项,就像老虎机一样。

There is just an Item_Appearing event that define the next appeared item in the list not the centered item. 只有Item_Appearing事件定义了列表中下一个出现的项目,而不是居中的项目。

This kind of features aren't really the forte of Forms so creating a custom control is probably your best option. 这种功能并不是Forms的特长,因此创建自定义控件可能是您的最佳选择。 If you aren't interested in doing that then I would tap into two things on the listview. 如果您对此不感兴趣,则可以在列表视图中进行两件事。

https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.listview.itemappearing?view=xamarin-forms https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.listview.itemappearing?view=xamarin-forms

Detect when items are appearing on the list, this way you can figure out what item is closest to the center. 检测项目何时出现在列表中,这样您就可以找出最靠近中心的项目。 Then use ScrollTo method to automatically center the item . 然后使用ScrollTo方法自动将项目居中 The biggest issue with this approach I see is detecting when the user has ended the scrolling as you don't want to center the item while the user is still scrolling. 我看到的这种方法的最大问题是检测用户何时结束滚动,因为您不想在用户仍在滚动时将项目居中。 If this is like slot machine where the user "pulls the handle" and the listviews scroll automatically you shouldn't have this issue. 如果这就像老虎机,用户在其中“拉动手柄”,并且列表视图自动滚动,那么您就不会遇到这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM