使drawable在图层列表中居中裁剪 [英] Make drawable do centerCrop in layer-list

查看:361
本文介绍了使drawable在图层列表中居中裁剪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部.

我想制作启动画面:

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/background_splash</item>
</style>

可绘制/背景飞溅:

<?xml version="1.0" encoding="utf-8"?>

<item
    android:drawable="@color/main_theme"/>

<item android:bottom="16dp">
    <bitmap
        android:gravity="center|fill_horizontal"
        android:src="@drawable/splash_logo"
        />
</item>

<item android:bottom="16dp">
    <bitmap
        android:gravity="bottom"
        android:src="@drawable/logo"/>
</item>

但是我无法使用android:src ="@ drawable/splash_logo"将位图调整为ImageView中的centerCrop比例(我需要将位图填满所有宽度)目前,它的大小与资源中的像素大小相同.如果我把它做大得多,它将更大的屏幕.我尝试了比例可绘制,没有任何意义.

But I have no ability to make bitmap with android:src="@drawable/splash_logo" resize as centerCrop scale in ImageView( I need my bitmap fill all width) For now it's size as size in resource in pixels. If i make it much larger it will be larger the screen. I tried scale drawable and no sense.

您有什么建议吗?

推荐答案

我能够实现填充屏幕,但是请记住,在18:9屏幕上会有点拉伸

I was able to achieve filling screen, but keep in mind, it will be a bit stretched on 18:9 screens

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="@drawable/splash_2_x2"
        android:top="0dp"
        android:bottom="0dp"
        android:left="0dp"
        android:right="0dp"/>
</layer-list>

这篇关于使drawable在图层列表中居中裁剪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆