如何解决图像在xaml页面和Android drawable上的中心不同
可绘制对象设置为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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。