I can't find a way to simply make my vector image 2/3 of the screen size without the madness with defining dimens.xml and using Java/Kotlin code.
Is it really impossible?
My current implementation of my splash screen:
drawable/splash.xml
:
<?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="#FFFFFF"/>
</shape>
</item>
<item android:drawable="@drawable/background0"
android:width="@dimen/logoSize"
android:height="@dimen/logoSize"
android:gravity="center"/>
</layer-list>
values/dimens.xml
:
<resources>
<dimen name="logoSize">240dp</dimen>
</resources>
values/apptheme.xml
:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
<item name="android:windowBackground">@drawable/splash</item>
</style>
</resources>
AndroidManifest.xml
:
<activity android:name="com.myapp.MainActivity"
android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density"
android:label="@string/app_name"
android:theme="@style/AppTheme"
it looks like this:
but when I try to replace drawable/splash.xml
with:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/background0"
/>
</LinearLayout>
green image does not appear. Is it possible to fix this?
Or probably is there some other way to use something like match_parent
+padding
with splash screen image, but make the image square somehow?
EDIT1 There is
android:scaleType="fitCenter"
but it works with ImageView, see Scale image keeping its aspect ratio in background drawable
EDIT2
Tried to add match_parent
to my vector image:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="match_parent"
android:height="match_parent"
android:viewportWidth="1000"
android:viewportHeight="1000">
...
but got build errors:
AAPT: error: 'match_parent' is incompatible with attribute height (attr) dimension.
AAPT: error: 'match_parent' is incompatible with attribute width (attr) dimension.