问题描述
可绘制对象设置为MainActivity主题,因此这是打开应用程序时首先看到的内容。
然后,该应用程序导航到SplashPage,在其中在后台运行一些代码。
我在两个屏幕的中央放置了一个图像。有一个高度差。我希望两个屏幕相同。
splash_screen.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/splash_background"/>
</item>
<item
android:height="400dp"
android:width="400dp"
android:gravity="center">
<bitmap
android:src="@drawable/circle"
android:gravity="fill"/>
</item>
</layer-list>
SplashPage.xaml
<?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="MyApp.Views.SplashPage"
BackgroundColor="{Binding BackgroundColor}">
<ContentPage.Content>
<AbsoluteLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Image Source="{Binding SplashImage}" WidthRequest="400" HeightRequest="400" Aspect="AspectFit" AbsoluteLayout.LayoutFlags="PositionProportional" AbsoluteLayout.LayoutBounds="0.5,0.5"/>
</AbsoluteLayout>
</ContentPage.Content>
</ContentPage>
解决方法
这是因为在主题中使用#![cfg_attr(feature = "backtraces",feature(backtrace))]
属性时,其绘制高度包含android:windowBackground
和Statusbar
的高度,而在Page.xaml中,绘制高度为设置在两者之间,因此高度有所不同。
解决方案:
更改
Navigationbar
到
<item name="android:windowBackground">@drawable/splash_screen</item>