good day

I do Splash Screen. In drawable I create an xml file in which I prescribe a background and a picture:

<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/orange"/> <item> <bitmap android:gravity="center" android:src="@drawable/logo_start"/> </item> </layer-list> 

Then I add this file to the styles:

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

How to set the size of bitmap? Or how to set the size for logo_start?

    1 answer 1

    Probably the most correct option is to create logo_start images with different sizes and put them in the appropriate folders:

    • drawable-mdpi
    • drawable-hdpi

    etc.

    For bitmap, you cannot specify the size, but you can make it fit on the screen (if you wanted to set the size in dp for this) as follows:

     <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/orange"/> <item android:left="20dp" android:right="20dp"> <bitmap android:src="@drawable/logo_start"/> </item> </layer-list> 

    In this case, a margin will be added around the bitmap, and the logo itself will be reduced by necessity.

    UPDATE: The problem is that the proportions of the logo will change, and this is bad.

    Another option is to use for this purpose the Image View. The basic layout will then be:

     <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:id="@+id/frame" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/orange"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:adjustViewBounds="true" android:scaleType="centerCrop" android:layout_margin="@dimen/activity_horizontal_margin" android:src="@drawable/logo_start"/> </FrameLayout> <!-- тут могут быть другие элементы, которые откроются после скрытия FrameLayout с id=frame --> </FrameLayout> 
    • android: left = "20dp and android: right =" 20dp "does not help the logo anyway vylazit beyond the screen: ( - Anatoly Ferisov
    • To help, you need to remove the android: gravity = "center" from the bitmap, but this method is also bad, since the logo is stretched disproportionately. Added another way with ImageView. - Alexey Timokhin