在闪屏中心裁剪制作背景图片

问题描述 投票:0回答:4

我使用图像作为我的启动画面的图片。

<style name="AppTheme.Launcher">
        <item name="android:windowBackground">@drawable/splash_screen</item>
</style>

但是,在某些不同的设备中,它已被拉伸和扭曲。有没有办法像ImageView一样制作照片中心?

android android-xml android-theme
4个回答
1
投票

如果您的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>

0
投票

用这个

<style name="AppTheme.Launcher">
    <item name="android:windowContentOverlay">@drawable/splash_screen</item>
</style>

0
投票

而不是直接设置图像,尝试从xml drawable设置它,这可能你可以更好地控制图像。

您可以按照此处显示的步骤操作: -

Splash the right way


0
投票

试试这个解决方案

首先得到不同大小的启动屏幕图像调整大小,并将它们放在像drawable这样的drawable-mpdi,drawable-hpdi,drawable-xhpdi,drawable-xxhpdi,drawable-xxxpdi文件夹中

directory like this

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>
© www.soinside.com 2019 - 2024. All rights reserved.