why splash screen in android doesn't fit inside the available space?

369 views Asked by At

I'm using the fallowing xml as splashScreen

<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <bitmap android:gravity="center" android:src="@drawable/splash" />
    </item>
</layer-list>

but width of the png(splash) is not fitting the screen width, it overflows if i set the gravity property or it stretches to whole screen if don't set the gravity, i dug up the whole stack overflow for 2 days. what am i doing wrong here

1

There are 1 answers

1
Nour Eldien Mohamed On

if you want to add image in the center

<androidx.constraintlayout.widget.ConstraintLayout 
    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:background="@color/colorPrimary"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.426"
        app:srcCompat="@drawable/ic_launcher_foreground" />


</androidx.constraintlayout.widget.ConstraintLayout>