在初始屏幕中心裁剪中制作背景图像

时间:2019-04-24 04:05:01

标签: android android-xml android-theme

我将图像用作斜线屏幕的图片。

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

但是,在某些不同的设备中,它已经拉伸并变形了。有没有办法像在ImageView中那样使照片居中裁剪?

4 个答案:

答案 0 :(得分:1)

如果可绘制对象是位图图像,则必须将可绘制对象资源的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>

答案 1 :(得分:0)

使用此

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

答案 2 :(得分:0)

与其直接设置图片,不如尝试通过xml drawable设置图片,这样可能会更好地控制图片。

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

Splash the right way

答案 3 :(得分:0)

尝试此解决方案

首先将初始屏幕图像调整为不同大小,然后将其放入request.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1); request.getParams().setParameter("http.protocol.content-charset", "UTF-8"); 之类的drawable文件夹中

directory like this

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
相关问题