当前位置: 首页 > 知识库问答 >
问题:

Xamarin型线效率

漆雕伟志
2023-03-14

XAML:

<ScrollView HorizontalOptions="Fill" Orientation="Horizontal">
                                <StackLayout Orientation="Vertical" BackgroundColor="GhostWhite" >
                                    <StackLayout Orientation="Horizontal" BackgroundColor="GhostWhite" >
                                        <Button HeightRequest="50" BackgroundColor="GhostWhite"  WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="dairy" Image="{Binding Dairy_Image}"/>
                                        <Button HeightRequest="50" BackgroundColor="GhostWhite"  WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="alcohol" Image="{Binding Alcohol_Image}"/>
                                        <Button HeightRequest="50" BackgroundColor="GhostWhite"  WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="eggs" Image="{Binding Egg_Image}"/>
                                        <Button HeightRequest="50" BackgroundColor="GhostWhite"  WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="fastfood" Image="{Binding Fastfood_Image}"/>
                                        <Button HeightRequest="50" BackgroundColor="GhostWhite"  WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="fish" Image="{Binding Fish_Image}"/>
                                        <Button HeightRequest="50" BackgroundColor="GhostWhite"  WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="fruit" Image="{Binding Fruit_Image}"/>
                                        <Button HeightRequest="50" BackgroundColor="GhostWhite"  WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="grain" Image="{Binding Grain_Image}"/>
                                        <Button HeightRequest="50" BackgroundColor="GhostWhite"  WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="legume" Image="{Binding Legume_Image}"/>
                                    </StackLayout>
                                    <StackLayout Orientation="Horizontal" BackgroundColor="GhostWhite" >
                                        <Button HeightRequest="50" BackgroundColor="GhostWhite"  WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="meat" Image="{Binding Meat_Image}"/>
                                        <Button HeightRequest="50" BackgroundColor="GhostWhite"  WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="munchies" Image="{Binding Munchies_Image}"/>
                                        <Button HeightRequest="50" BackgroundColor="GhostWhite"  WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="nuts" Image="{Binding Nut_Image}"/>
                                        <Button HeightRequest="50" BackgroundColor="GhostWhite"  WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="potato" Image="{Binding Potato_Image}"/>
                                        <Button HeightRequest="50" BackgroundColor="GhostWhite"  WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="soda" Image="{Binding Soda_Image}"/>
                                        <Button HeightRequest="50" BackgroundColor="GhostWhite"  WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="sweets" Image="{Binding Sweet_Image}"/>
                                        <Button HeightRequest="50" BackgroundColor="GhostWhite"  WidthRequest="50" Command="{Binding Button_Clicked_Food}" CommandParameter="vegetables" Image="{Binding Vegetable_Image}"/>
                                    </StackLayout>
                                </StackLayout>

.cs:

 public UserMealINC_vm(User_Profiles up, DateTime day)
        {
            try
            {
                Day = day;
                User_pro = up;
                Bool_Food_Type = false;
                Food_Name = "";
                Type = "";
                Food_Weight = "0";
                Selected_Food = new List<string>();

                //All meal item are first initialized with the non-coloured images
                Dairy_Image = "drawable/dairy.png";
                Alcohol_Image = "drawable/alcohol.png";
                Egg_Image = "drawable/eggs.png";
                Fastfood_Image = "drawable/fastfood.png";
                Fish_Image = "drawable/fish.png";
                Fruit_Image = "drawable/fruit.png";
                Grain_Image = "drawable/grain.png";
                Legume_Image = "drawable/legume.png";
                Meat_Image = "drawable/meat.png";
                Munchies_Image = "drawable/munchies.png";
                Nut_Image = "drawable/nuts.png";
                Potato_Image = "drawable/potato.png";
                Soda_Image = "drawable/soda.png";
                Sweet_Image = "drawable/sweets.png";
                Vegetable_Image = "drawable/vegetables.png";

                this.Button_Clicked_Food = new Command<string>((key) =>
                {
                    //Change the item selected from color to non-color, or vice-versa

                    if (Selected_Food.Contains(key))
                    {
                        if (key == "dairy")
                        {
                            Dairy_Image = "drawable/dairy.png";
                        }
                        else if (key == "alcohol")
                        {
                            Alcohol_Image = "drawable/alcohol.png";
                        }
                        else if (key == "eggs")
                        {
                            Egg_Image = "drawable/eggs.png";
                        }
                        else if (key == "fastfood")
                        {
                            Fastfood_Image = "drawable/fastfood.png";
                        }
                        else if (key == "fish")
                        {
                            Fish_Image = "drawable/fish.png";
                        }
                        else if (key == "fruit")
                        {
                            Fruit_Image = "drawable/fruit.png";
                        }
                        else if (key == "grain")
                        {
                            Grain_Image = "drawable/grain.png";
                        }
                        else if (key == "legume")
                        {
                            Legume_Image = "drawable/legume.png";
                        }
                        else if (key == "meat")
                        {
                            Meat_Image = "drawable/meat.png";
                        }
                        else if (key == "munchies")
                        {
                            Munchies_Image = "drawable/munchies.png";
                        }
                        else if (key == "nuts")
                        {
                            Nut_Image = "drawable/nuts.png";
                        }
                        else if (key == "potato")
                        {
                            Potato_Image = "drawable/potato.png";
                        }
                        else if (key == "soda")
                        {
                            Soda_Image = "drawable/soda.png";
                        }
                        else if (key == "sweets")
                        {
                            Sweet_Image = "drawable/sweets.png";
                        }
                        else if (key == "vegetables")
                        {
                            Vegetable_Image = "drawable/vegetables.png";
                        }
                        else
                        {
                            //Key out of bounds???
                        }

                        Selected_Food.Remove(key);
                    }
                    else
                    {
                        if (key == "dairy")
                        {
                            Dairy_Image = "drawable/dairy_color.png";
                        }
                        else if (key == "alcohol")
                        {
                            Alcohol_Image = "drawable/alcohol_color.png";
                        }
                        else if (key == "eggs")
                        {
                            Egg_Image = "drawable/eggs_color.png";
                        }
                        else if (key == "fastfood")
                        {
                            Fastfood_Image = "drawable/fastfood_color.png";
                        }
                        else if (key == "fish")
                        {
                            Fish_Image = "drawable/fish_color.png";
                        }
                        else if (key == "fruit")
                        {
                            Fruit_Image = "drawable/fruit_color.png";
                        }
                        else if (key == "grain")
                        {
                            Grain_Image = "drawable/grain_color.png";
                        }
                        else if (key == "legume")
                        {
                            Legume_Image = "drawable/legume_color.png";
                        }
                        else if (key == "meat")
                        {
                            Meat_Image = "drawable/meat_color.png";
                        }
                        else if (key == "munchies")
                        {
                            Munchies_Image = "drawable/munchies_color.png";
                        }
                        else if (key == "nuts")
                        {
                            Nut_Image = "drawable/nuts_color.png";
                        }
                        else if (key == "potato")
                        {
                            Potato_Image = "drawable/potato_color.png";
                        }
                        else if (key == "soda")
                        {
                            Soda_Image = "drawable/soda_color.png";
                        }
                        else if (key == "sweets")
                        {
                            Sweet_Image = "drawable/sweets_color.png";
                        }
                        else if (key == "vegetables")
                        {
                            Vegetable_Image = "drawable/vegetables_color.png";
                        }
                        else
                        {
                            //Key out of bounds???
                        }
                        Selected_Food.Add(key);
                    }
                });                
            }
            catch (Exception ex)
            {
                App.Current.MainPage.DisplayAlert("UserMealINC_vm 1!", ex.Message, "OK");
            }
        }

共有1个答案

潘嘉佑
2023-03-14

结果发现,我的应用程序中的多个图像都溢出了设备内存。(如@hvaughan3建议)

这个链接有它的答案。

您只需在Android清单(应用程序下)中添加这两行即可-

 类似资料:
  • 在搜索中,我看到的都是需要用户点击才能消失的警报。

  • 我正在尝试使用Xamarin表单订阅Azure服务总线队列。(说实话,我根本不确定是否有可能做到。) 我可以使用一个简单的控制台应用程序接收来自队列的消息,没有任何问题。但是,当我将相同的代码移动到Xamarin时,它在两种不同的场景中失败。 使用Xamarin是否可以正确订阅Azure服务总线队列? 我是不是漏了什么? 我是否有任何其他选择可以将JSON对象从服务总线发送到电话?

  • 怎么啦? 谢谢

  • 我试图找到使用Xamarin.Forms的解决方案,但其他问题中的解决方案不适用于Xamarin studio 5.9.6(更新后的版本5.9.7 build 22相同) 当我试图添加时,唯一可用的引用是xamarin.andoid.nunitlite 我得到错误cs0103 我试图通过以下链接安装4.6程序集http://www.microsoft.com/en-us/download/deta

  • Xamarin 允许你使用 .NET 代码和特定于平台的用户界面生成适用于 Android、iOS 和 macOS 的本机应用。 Xamarin.Forms 允许你使用采用 C# 或 XAML 编写的共享 UI 代码生成本机应用。

  • 本文向大家介绍xamarin 在OS X上安装Xamarin Studio,包括了xamarin 在OS X上安装Xamarin Studio的使用技巧和注意事项,需要的朋友参考一下 示例 在OS X机器上开始Xamarin开发的第一步是从官方网站下载并安装Xamarin Studio Community版本。如下图所示,需要填写一些字段来下载安装程序。 Xamarin Unified安装程序负责