【发布时间】:2020-10-29 17:27:50
【问题描述】:
我有一个独特的启动画面,名为 splash.png,大小为 1280x1280、150dpi
我在我的 React Native 项目中使用 react-native-bootsplash,但我认为这并不重要。
我的问题很简单:我怎样才能让我的启动画面在纵向模式下,全高,而不是更少,而不是更多,并保持其纵横比图片填满屏幕。
就像 css 中的 background-size: cover。
或者像 React Native 中的简单 <Image resizeMode="cover" style={{ height: '100%' }} />。
所以我有:
android/app/src/main/res/values/styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:textColor">#000000</item>
</style>
<!-- BootTheme should inherit from AppTheme -->
<style name="BootTheme" parent="AppTheme">
<!-- set the generated bootsplash.xml drawable as activity background -->
<item name="android:windowBackground">@drawable/bootsplash</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
android/app/src/main/res/drawable/bootsplash.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<item>
<!-- your logo, centered horizontally and vertically -->
<bitmap
android:layout_height="fill_parent"
android:src="@drawable/splash"
android:scaleType="centerInside"
android:gravity="center" />
</item>
</layer-list>
还有我的splash.pngandroid/app/src/main/res/drawable/splash.png
我尝试了很多东西,android:layout_height、android:scaleType 等等的很多组合,但我总是以飞溅图像的高度超出屏幕高度而告终。
[编辑] 这是初始图像,尺寸减小到足以使stackoverflow具有较小的尺寸
这是它在屏幕上显示的内容......
【问题讨论】:
-
你能贴一张你的启动画面吗?
-
尝试添加android:adjustViewBounds="true"
-
对于
item或bitmap? -
你可以试试
android:scaleType="centerCrop" -
对于
item或bitmap?
标签: android xml react-native react-native-android splash-screen