Android中的飞溅屏幕已拉伸

发布于 2025-02-04 09:19:08 字数 1040 浏览 0 评论 0原文

我添加了一个将要显示的飞溅屏幕,但总是将其伸展到边缘。如果屏幕不合格,我想夹紧它。

启动屏幕XML:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
   <item>
        <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
            android:gravity="fill|clip_horizontal"
            android:src="@drawable/splash_screen"/>
    </item>
</layer-list>

styles.xml

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
        <item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
    </style>

    <style name="SplashTheme" parent="AppTheme">
        <item name="android:windowBackground">@drawable/launch_screen</item>
    </style>

</resources>

我尝试了许多Android:Gravity的组合,但是我没有找到合适的组合。另外,我在互联网上发现的所有组合都不适合我。 我正在在Google Pixel 3A上进行测试,该分辨率与任何可绘制的飞溅图像都不适合。

是否可以剪辑图像?

I added a splash screen that will be displayed, but it is always stretched to the edge. I want to clip it if the screen doesn't fit.

Launch Screen Xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
   <item>
        <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
            android:gravity="fill|clip_horizontal"
            android:src="@drawable/splash_screen"/>
    </item>
</layer-list>

styles.xml

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
        <item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
    </style>

    <style name="SplashTheme" parent="AppTheme">
        <item name="android:windowBackground">@drawable/launch_screen</item>
    </style>

</resources>

I tried many combinations of android:gravity, but I didn't find the right one. Also, all combinations I found in the internet didn't work for me.
I am testing on a Google Pixel 3a which has a resolution that doesn't fit exact to any of the drawable splash images.

Is it possible to clip the image?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷雾森÷林ヴ 2025-02-11 09:19:08

我找不到解决方案,但是我拍摄了没有背景的公正图像,用XML添加背景并以此为中心:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

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

    <item
        android:width="161dp"
        android:height="70dp"
        android:drawable="@drawable/my_image"
        android:gravity="center" />

</layer-list>

I didn't find a solution how to crop it, but I took the just image without background, add the background with xml and center it like this:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

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

    <item
        android:width="161dp"
        android:height="70dp"
        android:drawable="@drawable/my_image"
        android:gravity="center" />

</layer-list>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文