1

I got a good answer on my previous question about resizing my vector splash screen image, but I wonder to know is it possible without using Java/Kotlin code for two reasons: 1) I am new to Android and I am not sure where to add the code, 2) I am not sure if the code does not slow down splash screen loading.

My idea is that I probably add an integer value as described here, but make it different depending on DPI (or screen size), it is possible?

And then I probably refer it from my splash screen as @myval:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle" >
            <!-- <solid android:color="#FF07862c"/> -->
            <gradient
                android:type="radial"
                android:startColor="#086824"
                android:endColor="#098a2f"
                android:gradientRadius="@myval"
                android:centerX="0.5"
                android:centerY="0.5"/>
        </shape>
    </item>
    <!-- <item android:drawable="@drawable/background0" android:gravity="center"/> -->
    <item android:drawable="@drawable/logo"
        android:width="@myval"
        android:height="@myval"
        android:gravity="center"/>
</layer-list>
Dmitriano
  • 1,878
  • 13
  • 29

1 Answers1

1

For such purpose, you can use dimen and alternative resources.

File structure:

res/
    values/
        dimens.xml
    values-sw600dp/
        dimens.xml

In each dimens.xml (XX or YY may be varied between in values/dimens and in values-sw600dp/dimens):

<resources>
    <dimen name="logoWidth">XXdp</dimen>
    <dimen name="logoHeight">YYdp</dimen>
</resources>

Usage in layout.xml:

<item android:drawable="@drawable/logo"
        android:width="@dimen/logoWidth"
        android:height="@dimen/logoHeight"
        android:gravity="center"/>
hata
  • 11,633
  • 6
  • 46
  • 69
  • Thanks! I do not have an idea why does not Android allow to refer screen width and height directly from xml. – Dmitriano Dec 28 '21 at 11:57
  • Or probably make the image full screen somehow... https://stackoverflow.com/questions/6918430/splash-screenhow-to-show-an-image-in-full-screen – Dmitriano Dec 28 '21 at 12:04