arn*_*bro 12 xml android splash-screen react-native react-native-android
我有一个独特的启动画面,名为 splash.png,大小为 1280x1280, 150dpi,我react-native-bootsplash
在 React Native 项目中使用,但我认为这并不重要。
我的问题很简单:如何使我的启动画面在纵向模式下成为全高,而不是更少,而不是更多,并保持其纵横比,以便图片填满屏幕。就像background-size: cover
在 css 中一样。或者像一个简单的<Image resizeMode="cover" style={{ height: '100%' }} />
React Native 中。
所以我有 :
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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
而我splash.png
的android/app/src/main/res/drawable/splash.png
我尝试了很多东西,很多组合android:layout_height
,android:scaleType
和所有,我总是以初始图像的高度溢出屏幕高度结束。
[编辑] 这是初始图像,大小减小到足以使 stackoverflow 变小
这是它在屏幕上给出的内容......
我认为这里的关键是android:gravity="fill"
。
当我在我的应用程序中实现它时,我遇到了同样的问题。
我的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>
<style name="BootTheme" parent="AppTheme">
<!-- set bootsplash.xml as background -->
<item name="android:background">@drawable/bootsplash</item>
Run Code Online (Sandbox Code Playgroud)
和我的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:opacity="opaque">
<item>
<bitmap android:src="@mipmap/launch_screen" android:gravity="fill" />
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5892 次 |
最近记录: |