加载网格儿童需要太长时间的xamarin.forms

时间:2016-12-09 22:38:16

标签: c# xamarin xamarin.forms

所以我正在开发一个xamarin表单的应用程序,在我的便携式类中,有一个页面有一个网格,我想加载90个孩子,其中都有几个图像,View被称为NumberBlock但是它加载页面需要3-4秒,这在Android手机上运行时会导致延迟(没有尝试其他人):

这是NumberBlock视图:

#define THIS_CLASS mystruct

struct THIS_CLASS {

  THIS_CLASS (){}
};

#undef mystruct

这是我加载创建网格的方式:

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="NumbersRaceXamarin.NumberBlock">
  <ContentView.Content>
    <StackLayout HeightRequest="90" WidthRequest="44" Spacing="5">
      <Image x:Name="pin" Source="push_pin.png" HeightRequest="21" WidthRequest="21" ></Image>
      <RelativeLayout HorizontalOptions="Center" >
        <BoxView x:Name="selectedRect" HeightRequest="42" WidthRequest="42" Color="Blue" Opacity="0"/>
        <Label x:Name="numberTB" Text="" IsVisible="false"/>
        <Image  Source="block.png" HeightRequest="42" WidthRequest="42" ></Image>
        <Image x:Name="digit"   HeightRequest="40" WidthRequest="40" RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height , Factor=0.03,Constant=0}" RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width , Factor=0.03,Constant=0}"></Image>
      </RelativeLayout>
      <Image x:Name="link" Source="linkicon_01.png" HeightRequest="14" WidthRequest="31" Opacity="0"></Image>
    </StackLayout>
  </ContentView.Content>
</ContentView>

这就是我运行refresh方法的方法:

    public void refresh(Player pl)
    {
            LevelsGrid.Children.Clear();
            for (int i = 0; i < LevelManager.levels.Count; i++)
            {
                int kind = 2;
                if (i > pl.completedLevels.Count)
                {
                    kind = 0;
                }
                else if (i == pl.completedLevels.Count)
                {
                    kind = 1;
                }

                levelBlock bt = new levelBlock(kind, LevelManager.levels[i].levelName.Remove(0, 5));
                bt.HeightRequest = 40;
                bt.WidthRequest = 40;
                var tapGestureRecognizer = new TapGestureRecognizer();

                tapGestureRecognizer.Tapped += levelClick;
                bt.GestureRecognizers.Add(tapGestureRecognizer);
                LevelsGrid.Children.Add(bt, i % 8, i / 8);
            }
        coinsOwnedTB.Text = pl.coins + "";
        scoreTB.Text = pl.score + "";
    }

我的问题是:

1)无论如何更有效率地做我正在做的事情会使过程变得更快(在某种程度上可能在后台运行!?)

2)如果没有办法让它更快,是否有办法让页面出现,然后网格逐渐加载?

谢谢

0 个答案:

没有答案
相关问题