【发布时间】:2021-05-03 10:10:25
【问题描述】:
我使用 Xamarin.Forms 创建了一个导航侧边栏应用程序,甚至在我对项目进行任何更改之前,我就发现出了点问题。当我在计算机上启动 Pixel 2 模拟器时,我看到以下 正确 视图。
但是,当我发送 APK 或将其附加到我的计算机并调试程序时,我注意到标签没有出现,如下面我的 OnePlus 8T + 5G (Android 11) 上的屏幕截图所示。
我的手机和模拟器之间显然有很多不同之处,但在大多数情况下,所有设备上的差异应该是相同的,并且应用程序确实加载了其他元素(如按钮和图像)正确。这是怎么回事?
我尝试过的事情
- 搜索其他帖子,例如 this one,在模拟器和手机上显示不同的结果。不走运。
- 在 Debug/Release 和更改 APK 首选项之间切换以避免代码压缩和可能的数据丢失。不走运。
这是代码。
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Car_Scan.Views.BrowsePage"
xmlns:vm="clr-namespace:Car_Scan.ViewModels"
Title="{Binding Title}">
<ContentPage.BindingContext>
<vm:AboutViewModel />
</ContentPage.BindingContext>
<ContentPage.Resources>
<ResourceDictionary>
<Color x:Key="Accent">#96d1ff</Color>
</ResourceDictionary>
</ContentPage.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackLayout BackgroundColor="{StaticResource Accent}" VerticalOptions="FillAndExpand" HorizontalOptions="Fill">
<StackLayout Orientation="Horizontal" HorizontalOptions="Center" VerticalOptions="Center">
<ContentView Padding="0,40,0,40" VerticalOptions="FillAndExpand">
<Image Source="xamarin_logo.png" VerticalOptions="Center" HeightRequest="64" />
</ContentView>
</StackLayout>
</StackLayout>
<ScrollView Grid.Row="1">
<StackLayout Orientation="Vertical" Padding="30,24,30,24" Spacing="10">
<Label Text="Start developing now" FontSize="Title"/>
<Label Text="Make changes to your XAML file and save to see your UI update in the running app with XAML Hot Reload. Give it a try!" FontSize="16" Padding="0,0,0,0"/>
<Label FontSize="16" Padding="0,24,0,0">
<Label.FormattedText>
<FormattedString>
<FormattedString.Spans>
<Span Text="Learn more at "/>
<Span Text="https://aka.ms/xamarin-quickstart" FontAttributes="Bold"/>
</FormattedString.Spans>
</FormattedString>
</Label.FormattedText>
</Label>
<Button Margin="0,10,0,0" Text="Learn more"
Command="{Binding OpenWebCommand}"
BackgroundColor="{StaticResource Primary}"
TextColor="White" />
</StackLayout>
</ScrollView>
</Grid>
</ContentPage>
【问题讨论】:
-
你有没有想过这个问题?我有一个非常相似的问题。
标签: android xamarin.forms android-emulator