У меня проблема только на Android.Мои элементы в Listview иногда не обновляются.Я открываю вид и вижу элемент без текста или пробела (экран 1-2).Я прокручиваю вниз, а затем прокручиваю вверх.Элемент перерисовывается и отображается текст или удаляется пробел (экран 3) Как это исправить?Ниже приведены фотографии:
https://i.stack.imgur.com/iv0RC.png
https://i.stack.imgur.com/Kdjs8.png
https://i.stack.imgur.com/FJ4JJ.png
Мой список:
<Grid BackgroundColor="{Binding ListViewCustomizer.DefaultBackgroundColor}">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<recycle:RecycleListView ItemsSource="{Binding NewsFeedItems}"
VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
ShowAdvertisementEvery="10"
ItemSelected="HandleItemSelected" RefreshCommand="{Binding RefreshCommand}"
RowSpacing="0" ItemMargin="0"
LoadMoreCommand="{Binding LoadMoreCommand}"
IsLoadMoreEnabled="True"
IsLoadingMore="{Binding IsOldestLoading}"
IsRefreshing="{Binding IsRefreshing}"
IsPullToRefreshEnabled="True">
<recycle:RecycleListView.IsAdvertisementEnabled>
<OnPlatform x:TypeArguments="x:Boolean">
<OnPlatform.iOS>
false
</OnPlatform.iOS>
<OnPlatform.Android>
true
</OnPlatform.Android>
</OnPlatform>
</recycle:RecycleListView.IsAdvertisementEnabled>
<recycle:RecycleListView.ItemHeight>
<extensions:OnDeviceType x:TypeArguments="x:Double" Phone="130" Tablet="200"/>
</recycle:RecycleListView.ItemHeight>
<recycle:RecycleListView.Padding>
<OnPlatform x:TypeArguments="Thickness">
<OnPlatform.iOS>
0, 0, 0, 0
</OnPlatform.iOS>
<OnPlatform.Android>
0, 0, 0, 5
</OnPlatform.Android>
</OnPlatform>
</recycle:RecycleListView.Padding>
<recycle:RecycleListView.ItemTemplate>
<DataTemplate>
<viewCells:NewsFeedListItem/>
</DataTemplate>
</recycle:RecycleListView.ItemTemplate>
</recycle:RecycleListView> </Grid>
Там RecycleListView является средством визуализации.
Средство визуализации:
protected RecyclerView _recyclerView;
protected RecycleListViewAdapter _adapter;
protected SwipeRefreshLayout _refresh;
protected RecyclerView.ItemDecoration _itemDecoration;
protected RecycleScrollListener _scrollListener;
protected override void OnElementChanged(ElementChangedEventArgs<RecycleListView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
CreateNativeElement();
SetNativeControl(_refresh);
}
}
protected void CreateNativeElement()
{
_recyclerView = new RecyclerView(Android.App.Application.Context);
_recyclerView.HasFixedSize = true;
_recyclerView.SetLayoutManager(new LinearLayoutManager(Context, OrientationHelper.Vertical, false));
_recyclerView.SetItemAnimator(new DefaultItemAnimator());
_recyclerView.HorizontalScrollBarEnabled = false;
_recyclerView.VerticalScrollBarEnabled = true;
var pool = _recyclerView.GetRecycledViewPool();
pool.SetMaxRecycledViews(RecycleListViewAdapter.ADVERTISEMENT_VIEW_TYPE, 1);
pool.SetMaxRecycledViews(RecycleListViewAdapter.DEFAULT_VIEW_TYPE, 25);
_scrollListener = new RecycleScrollListener();
_scrollListener.Loading += (object sender, EventArgs args) => { OnLoadMore(); };
UpdateIsLoadMoreEnabled();
_adapter = new RecycleListViewAdapter(
Context,
Element.ItemsSource,
_recyclerView,
Element,
Resources.
DisplayMetrics,
Element.IsAdvertisementEnabled,
Element.ShowAdvertisementEvery);
_recyclerView.SetAdapter(_adapter);
_itemDecoration = new SpacesItemDecoration(
ConvertDpToPixels(Element.RowSpacing),
ConvertDpToPixels(Element.ItemMargin.Left),
ConvertDpToPixels(Element.ItemMargin.Top),
ConvertDpToPixels(Element.ItemMargin.Right),
ConvertDpToPixels(Element.ItemMargin.Bottom)
);
_recyclerView.AddItemDecoration(_itemDecoration);
_refresh = new SwipeRefreshLayout(Android.App.Application.Context);
_refresh.SetOnRefreshListener(this);
_refresh.AddView(_recyclerView, LayoutParams.MatchParent);
}