示例#1
0
        private TextView GetTextView()
        {
            var param = PixelConverter.GetParamsRelative(ViewGroup.LayoutParams.MatchParent, PixelConverter.DpToPX(320),
                                                         10, 160, 10, 10);

            ViewModel.CurrentNumber = new Random(unchecked ((int)DateTime.Now.Ticks)).Next(ViewModel.Database.Count);
            var randIndex =
                (ViewModel.CurrentNumber +
                 new Random(unchecked ((int)DateTime.Now.Ticks)).Next(1, ViewModel.Database.Count)) %
                ViewModel.Database.Count;

            ViewModel.Answer = new Random(unchecked ((int)DateTime.Now.Ticks)).Next(2) == 1 ? true : false;
            var translationWord = ViewModel.Database[ViewModel.Answer ? ViewModel.CurrentNumber : randIndex]
                                  .TranslationWord;
            var textView = new TextView(this)
            {
                TextSize         = 30,
                Elevation        = PixelConverter.DpToPX(10),
                LayoutParameters = param,
                Text             = $"{ViewModel.Database[ViewModel.CurrentNumber].Word}\n\n{translationWord}",
                Gravity          = GravityFlags.CenterHorizontal | GravityFlags.Center
            };

            textView.Background = BackgroundWord;
            textView.SetTextColor(Colors.White);
            return(textView);
        }