xamarin - 图像在 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>
解决方案
这是因为当您android:windowBackground
在主题中使用该属性时,其绘制高度包含 和 的高度Statusbar
,Navigationbar
而在 Page.xaml 中绘制高度设置在两者之间,因此存在高度差异。
解决方案:
改变
<item name="android:windowBackground">@drawable/splash_screen</item>
至
<item name="android:background">@drawable/splash_screen</item>
推荐阅读
- python - WebDriverWait on javascript 值
- collections - 在异构 Rust 集合中使用 Any trait 对象有什么问题?
- c++ - 通过 unique_ptr 和自定义删除器使用自动扣除
- python - 如何通过 Selenium 和 Python 根据 HTML 单击引导按钮
- firebase - 如何通过 Facebook 提供商更新身份验证帐户的电话号码
- c# - Oracle ODP.NET 和 Visual Studio:连接问题
- javascript - 如何在玉中连接数组?
- sql-server - 逆序排列订单数量
- javascript - 使用 jQuery 将表单中的变量作为 Street View API 参数传递的问题
- sails.js - Sails JS 策略没有响应