我不是在寻找解决方案,因为我相信在我的具体情况下,你们没有什么可以收集到导致这种情况的原因。但我想知道是否有人对这可能发生的事情有任何见解。我们每天有8K +用户。这个问题似乎只影响了我们用户的一小部分,而且似乎只发生在wifi上。但基本上,这就是他们所看到的:
所以它显示了列表视图的项目源的路径。而不是它应该显示的布局。布局非常复杂,所以我最初不会发布它,但如果有人想看到它,那么我肯定会在这里发布它。只是真的在这里寻找见解。它似乎只发生在我们显示图像时(我们为不想看图像的用户提供了另一个列表视图)。
更新(CustomGridCell)
这是我的布局:
ImageFrame = new XamarinMobile.CustomRenderers.ExtendedFrame();
FrameContainer = new Xamarin.Forms.AbsoluteLayout();
ImageAndOverlayContainer = new Xamarin.Forms.AbsoluteLayout();
ShowReadOverlay = new Xamarin.Forms.BoxView();
headline = new Xamarin.Forms.Label();
headline.VerticalOptions = Xamarin.Forms.LayoutOptions.Center;
headline.HorizontalOptions = Xamarin.Forms.LayoutOptions.StartAndExpand;
headline.TranslationX = 0;
headline.TextColor = App.IsDarkThemeEnabled() ? Xamarin.Forms.Color.White : Xamarin.Forms.Color.Black;
headline.FontSize = App.IsLargeTextEnabled() ? App.NormalizeFontSize(20) : App.NormalizeFontSize(16);
loadingMoreStories = new Xamarin.Forms.Label();
loadingMoreStories.VerticalOptions = Xamarin.Forms.LayoutOptions.Center;
loadingMoreStories.HorizontalOptions = Xamarin.Forms.LayoutOptions.StartAndExpand;
loadingMoreStories.TranslationX = 0;
loadingMoreStories.TextColor = App.IsDarkThemeEnabled() ? Xamarin.Forms.Color.White : Xamarin.Forms.Color.Black;
loadingMoreStories.FontSize = App.IsLargeTextEnabled() ? App.NormalizeFontSize(20) : App.NormalizeFontSize(16);
publishDate = new Xamarin.Forms.Label();
publishDate.VerticalOptions = Xamarin.Forms.LayoutOptions.Center;
publishDate.HorizontalOptions = Xamarin.Forms.LayoutOptions.StartAndExpand;
publishDate.TranslationX = 0;
publishDate.TextColor = App.IsDarkThemeEnabled() ? Xamarin.Forms.Color.White : Xamarin.Forms.Color.Gray;
publishDate.FontSize = App.IsLargeTextEnabled() ? App.NormalizeFontSize(16) : App.NormalizeFontSize(12);
cellImage = new Xamarin.Forms.Image();
loadingText = new Xamarin.Forms.Label();
loadingText.Text = "Loading...";
loadingText.TextColor = App.IsDarkThemeEnabled() ? Xamarin.Forms.Color.White : Xamarin.Forms.Color.Gray;
GoogleAdView = new Xamarin.Forms.ContentView();
activityIndicator = new Xamarin.Forms.ActivityIndicator()
{
IsEnabled = false,
IsRunning = false,
Color = Xamarin.Forms.Color.Red
};
GoogleAd = new Controls.Ad();
GoogleAdView.Content = GoogleAd;
GoogleAd.AdFailed = (r) =>
{
};
GoogleAd.AdReturned = (r) =>
{
};
layout = new Xamarin.Forms.Grid();
AdContainer = new Xamarin.Forms.Grid();
LoadingLayout = new Xamarin.Forms.StackLayout()
{
VerticalOptions = Xamarin.Forms.LayoutOptions.Center,
BackgroundColor = Xamarin.Forms.Color.Transparent,
HorizontalOptions = App.Settings.SettingsValues.GridListView ? Xamarin.Forms.LayoutOptions.Start : Xamarin.Forms.LayoutOptions.Center,
Orientation = Xamarin.Forms.StackOrientation.Vertical,
Children =
{
headline,
publishDate,
loadingMoreStories
}
};
layout.RowDefinitions.Add(new Xamarin.Forms.RowDefinition { Height = new Xamarin.Forms.GridLength(1, Xamarin.Forms.GridUnitType.Star) });
layout.ColumnDefinitions.Add(new Xamarin.Forms.ColumnDefinition { Width = new Xamarin.Forms.GridLength(1, Xamarin.Forms.GridUnitType.Star) });
layout.Children.Add(loadingText, 0, 0);
//Facebook Ads
FacebookAdContainer = new Xamarin.Forms.StackLayout();
FacebookAd = new Controls.FacebookAd();
FacebookAd.PlacementId = $"{App.FacebookPlacementId}";
FacebookAd.VerticalOptions = Xamarin.Forms.LayoutOptions.CenterAndExpand;
FacebookAd.Page = MobileObjects.Enums.PageType.Grid;
FacebookAdContainer.Children.Add(FacebookAd);
AdContainer.Children.Add(GoogleAdView, 0, 0);
AdContainer.Children.Add(FacebookAdContainer, 0, 0);
layout.Children.Add(AdContainer, 0, 0);
//ugh, we need to do an image frame because thats the only way (that I know of) to add a border on an image. We need this if the image is older than x, because they no longer have borders.
ImageFrame.Padding = new Xamarin.Forms.Thickness(0);
ShowReadOverlay.HeightRequest = 0;
ImageAndOverlayContainer.Children.Add(cellImage);
ImageAndOverlayContainer.Children.Add(ShowReadOverlay);
ImageFrame.Content = ImageAndOverlayContainer;
ImageFrame.HasShadow = false;
FrameContainer.HorizontalOptions = Xamarin.Forms.LayoutOptions.CenterAndExpand;
FrameContainer.Children.Add(ImageFrame);
layout.Children.Add(FrameContainer, 0, 0);
layout.Children.Add(ShowReadOverlay, 0, 0);
layout.Children.Add(LoadingLayout, 0, 0);
loadingText.HorizontalOptions = Xamarin.Forms.LayoutOptions.CenterAndExpand;
loadingText.VerticalOptions = Xamarin.Forms.LayoutOptions.CenterAndExpand;
cellImage.HorizontalOptions = Xamarin.Forms.LayoutOptions.CenterAndExpand;
cellImage.VerticalOptions = Xamarin.Forms.LayoutOptions.CenterAndExpand;
if (!hasLoadedAdAtLeastOnce)
{
hasLoadedAdAtLeastOnce = true;
}
layout.Padding = new Xamarin.Forms.Thickness(App.HorizontalGridPadding);
LoadingLayout.WidthRequest = 280;
GoogleAdView.Content.HorizontalOptions = Xamarin.Forms.LayoutOptions.Center;
View = layout;
更新2(如何连线)
foreach (MobileObjects.GridListStory story in stories.StoryList)
{
index++;
//if (index % (adLocation + 1) == 0 && index != stories.StoryList.Count)
if (index == _firstadlocation + 1)
{
PhoneCells.Add(new ViewModels.GridCellViewModel { Image = string.Empty, HasRead = false, Headline = "Loading Ad...", PublishDate = string.Empty, ActivityIndicator = new Xamarin.Forms.ActivityIndicator(), IsAd = true, ShowFacebookAd = App.Settings.SettingsValues.AdNetwork == MobileObjects.Enums.AdNetwork.facebook, rawCellIndex = index, collectionIndex = 0, numberOfStories = stories.StoryList.Count, LoadPageDate = LoadPageDate, StoryId = 0, IsEndOfGrid = IsEndOfGrid });
_numberOfAds++;
}
else
{
if (_subsequentadlocation != 0 && index != _subsequentadlocation && index != _firstadlocation && ((index - (_firstadlocation)) % _subsequentadlocation == 0) && (index != stories.StoryList.Count || index != stories.StoryList.Count - 1))
{
PhoneCells.Add(new ViewModels.GridCellViewModel { Image = string.Empty, HasRead = false, Headline = "Loading Ad...", PublishDate = string.Empty, ActivityIndicator = new Xamarin.Forms.ActivityIndicator(), IsAd = true, ShowFacebookAd = App.Settings.SettingsValues.AdNetwork == MobileObjects.Enums.AdNetwork.facebook, rawCellIndex = index, collectionIndex = 0, numberOfStories = stories.StoryList.Count, LoadPageDate = LoadPageDate, StoryId = 0, IsEndOfGrid = IsEndOfGrid });
_numberOfAds++;
}
}
try
{
ViewModels.GridCellViewModel newCell = new ViewModels.GridCellViewModel { Image = story.SquareImageURL, ImageWidth = story.SquareWidth, HasRead = story.ReadStory, Headline = story.Headline, PublishDate = story.AddedDateString, ActivityIndicator = new Xamarin.Forms.ActivityIndicator(), IsAd = false, rawCellIndex = index, collectionIndex = _index, numberOfStories = stories.StoryList.Count, LoadPageDate = LoadPageDate, StoryId = story.StoryId, IsEndOfGrid = IsEndOfGrid };
PhoneCells.Add(newCell);
//we could set these properties in the view model object above, but to make it easier to maintain, we're using a controller which will be the endpoint for any time we want to mark a story as read.
XamarinMobile.Controllers.SIRController.ChangeBGColor(story.ReadStory, PhoneCells[PhoneCells.Count - 1]);
XamarinMobile.Controllers.SIRController.ChangeTextColor(story.ReadStory, PhoneCells[PhoneCells.Count - 1]);
}
catch (System.Exception ex)
{
var j = ex;
}
_index++;
if (index == stories.StoryList.Count)
{
_lastStoryIdOfGrid = story.StoryId;
}
}
PhoneCells.Add(new ViewModels.GridCellViewModel { Image = string.Empty, HasRead = false, Headline = string.Empty, PublishDate = string.Empty, ActivityIndicator = new Xamarin.Forms.ActivityIndicator(), IsAd = false, collectionIndex = 0, rawCellIndex = stories.StoryList.Count + 1, numberOfStories = stories.StoryList.Count, LoadPageDate = LoadPageDate, StoryId = 0, IsEndOfGrid = IsEndOfGrid });
SetUpGridNumberAndName();
_navigatingToPage = false;
Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
{
gridList.IsVisible = true;
gridList.ItemTemplate = new DataTemplate(typeof(Classes.CustomGridCell));
gridList.ItemsSource = PhoneCells;
App.GridCells = PhoneCells;
var adCells = PhoneCells.Where(x => x.IsAd);
if (adCells != null)
{
App.GridAdCells = new System.Collections.ObjectModel.ObservableCollection<ViewModels.GridCellViewModel>(adCells.ToList());
}
});
更新3(GridCellViewModel)
public class GridCellViewModel : System.ComponentModel.INotifyPropertyChanged
{
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
private Xamarin.Forms.Color _backgroundColor;
public Xamarin.Forms.Color BackgroundColor
{
get { return _backgroundColor; }
set
{
if(HasRead)
{
_backgroundColor = value;
} else
{
_backgroundColor = Xamarin.Forms.Color.Transparent;
}
PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs("BackgroundColor"));
}
}
private Xamarin.Forms.Color _textColor;
public Xamarin.Forms.Color TextColor
{
get { return _textColor; }
set
{
if (HasRead)
{
_textColor = value;
}
else
{
if(App.IsDarkThemeEnabled())
{
_textColor = Xamarin.Forms.Color.White;
} else
{
_textColor = Xamarin.Forms.Color.Black;
}
}
PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs("TextColor"));
}
}
public string Image { get; set; }
public string Headline { get; set; }
public string PublishDate { get; set; }
public Xamarin.Forms.ActivityIndicator ActivityIndicator { get; set; }
public bool IsAd { get; set; }
public bool HasRead { get; set; }
public bool AdHasLoaded { get; set; } = false;
public int collectionIndex { get; set; }
public int rawCellIndex { get; set; }
public int numberOfStories { get; set; }
public DateTime LoadPageDate { get; set; }
public int StoryId { get; set; }
public bool IsEndOfGrid { get; set; }
//next 2 properties only used for tablets
public int ImageWidth { get; set; }
public int ImageHeight { get; set; }
private Guid _adIdentification = Guid.NewGuid();
public Guid AdIdentification
{
get
{
return _adIdentification;
}
}
private MobileObjects.Enums.AdNetwork _adNetwork;
public MobileObjects.Enums.AdNetwork AdNetwork
{
get
{
return App.Settings.SettingsValues.AdNetwork;
}
}
private bool _showFacebookAd = true;
public bool ShowFacebookAd
{
get { return _showFacebookAd; }
set
{
_showFacebookAd = value;
PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs("ShowFacebookAd"));
}
}
private bool _showGoogleAd = false;
public bool ShowGoogleAd
{
get { return _showGoogleAd; }
set
{
if (value == true)
{
//attempt to load ad???
}
_showGoogleAd = value;
PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs("ShowGoogleAd"));
}
}