我使用图像作为我的启动画面的图片。
<style name="AppTheme.Launcher">
<item name="android:windowBackground">@drawable/splash_screen</item>
</style>
但是,在某些不同的设备中,它已被拉伸和扭曲。有没有办法像ImageView一样制作照片中心?
如果您的drawable是位图图像,那么您必须在drawable资源的android:gravity
元素上将"center"
属性更改为bitmap
。
默认值为"fill"
,“如果需要,可以增大对象的水平和垂直尺寸,以便完全填充其容器。” More xml bitmap info。
例如drawable / background_splash.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/colorAccent"></color>
</item>
<item>
<bitmap
android:src="@drawable/logo"
android:gravity="center"
android:antialias="true"
/>
</item>
</layer-list>
用这个
<style name="AppTheme.Launcher">
<item name="android:windowContentOverlay">@drawable/splash_screen</item>
</style>
试试这个解决方案
首先得到不同大小的启动屏幕图像调整大小,并将它们放在像drawable
这样的drawable-mpdi,drawable-hpdi,drawable-xhpdi,drawable-xxhpdi,drawable-xxxpdi
文件夹中
360x640 - mdpi
540x960 - hpdi
720x1280 - xhpdi
1080x1920 - xxhpdi
1440x2560 - xxxhpdi
然后在xml
的飞溅活动
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash_screen">
</RelativeLayout>
或者只是为特定活动定义风格的drawable
<style name="AppTheme.Launcher">
<item name="android:windowBackground">@drawable/splash_screen</item>
</style>