Заставка заужена внутри

Я использовал изображение в качестве фона экрана-заставки, его размер был изменен для разной плотности пикселей:

hdpi - 480x800 mdpi - 320x480 xhdpi - 768x1280 xxhdpi- 1080x1920 xxxhdpi - 1440x2560

splash_screen.xml

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">

    <item android:drawable="@drawable/launcher"/>

</layer-list>

styles.xml

    <style name="AppTheme.Launcher" parent="BaseAppTheme">
        <item name="android:windowBackground">@drawable/splash_screen</item>
        <item name="colorPrimaryDark">@color/grey_light</item>
    </style>

Он отлично работает на эмуляторе, но на Samsung Galaxy M20, A7, S9 и т. Д. (Разрешение 2340x1080, плотность экрана xhdpi) внутри выглядит суженным. Любое решение для этого?

Nexus 4 (xhdpi)

Samsung Galaxy M20 (xhdpi)

AndroidManifest.xml

<activity
      android:name="com.demo.app.MainActivity"
      android:configChanges="orientation|screenSize"
      android:theme="@style/AppTheme.Launcher"
      android:label="@string/app_name">
      <intent-filter>
          <action android:name="android.intent.action.MAIN" />

          <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
</activity>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <RelativeLayout xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/drawer_child"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".ui.MainActivity">

        <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/bottomHolder"
            android:fitsSystemWindows="false">

            <include layout="@layout/toolbar_tabbar" />

            <include layout="@layout/activity_main_content" />

        </androidx.coordinatorlayout.widget.CoordinatorLayout>

        <LinearLayout
            android:id="@+id/bottomHolder"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="@color/white"
            android:elevation="@dimen/bottombar_elevation"
            android:orientation="vertical">

            <com.google.android.material.bottomnavigation.BottomNavigationView
                android:id="@+id/bottom_navigation"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="gone"
                app:menu="@menu/activity_main_drawer" />

            <com.google.android.gms.ads.AdView
                android:id="@+id/adView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="gone"
                app:adSize="BANNER"
                app:adUnitId="@string/admob_banner_id" />

        </LinearLayout>

    </RelativeLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/myDrawerBackground"
        android:fitsSystemWindows="true"
        app:itemBackground="@drawable/drawer_item_background"
        app:headerLayout="@layout/drawer_top"
        app:menu="@menu/activity_main_drawer"
        android:theme="@style/NavigationViewStyle"/>

</androidx.drawerlayout.widget.DrawerLayout>

activity_main_content.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_height="match_parent"
tools:context=".MainActivity"
tools:showIn="@layout/activity_main"
app:layout_behavior="com.demo.app.util.CustomScrollingViewBehavior">

<com.demo.app.util.layout.DisableableViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</com.demo.app.util.layout.DisableableViewPager>

</RelativeLayout>


person Cattaleya    schedule 06.05.2020    source источник
comment
@IntelliJAmiya нет, внутри все еще сужено, скриншот в моем последнем комментарии под вашим ответом   -  person Cattaleya    schedule 07.05.2020
comment
Покажите нам свой xml, пожалуйста   -  person IntelliJ Amiya    schedule 07.05.2020
comment
я скопировал splash_screen.xml и разместил выше вместе со стилями.xml   -  person Cattaleya    schedule 07.05.2020
comment
Куда вы звоните splash_screen xml. Пожалуйста, предоставьте основной xml   -  person IntelliJ Amiya    schedule 07.05.2020
comment
@IntelliJAmiya в AndroidManifest.xml, опубликованном выше.   -  person Cattaleya    schedule 07.05.2020
comment
предоставьте скриншот, это поможет   -  person Ajay Chauhan    schedule 07.05.2020
comment
Пожалуйста, предоставьте основной xml вашей деятельности   -  person IntelliJ Amiya    schedule 07.05.2020
comment
@IntelliJAmiya вверх   -  person Cattaleya    schedule 07.05.2020
comment
Показать activity_main_content   -  person IntelliJ Amiya    schedule 07.05.2020
comment
@IntelliJAmiya вверх   -  person Cattaleya    schedule 07.05.2020
comment
Вызов отрисовки splash_screen из любых тегов ImageView?   -  person IntelliJ Amiya    schedule 07.05.2020
comment
нет, он вызывается только в splash_screen.xml. Дело в том, что есть устройства с разным разрешением экрана, которые используют чертежи из папки xhdpi. Он отлично смотрится на эмуляторе Nexus 4, но сужается на Samsung Galaxy M20, у которого экран тоньше и длиннее.   -  person Cattaleya    schedule 07.05.2020
comment
@IntelliJAmiya есть идеи?   -  person Cattaleya    schedule 08.05.2020


Ответы (1)


Прочтите официальное руководство по Support different pixel densities.

Чтобы обеспечить хорошее качество графики на устройствах с разной плотностью пикселей, вы должны предоставить несколько версий каждого растрового изображения в своем приложении - по одной для каждого сегмента плотности с соответствующим разрешением.

drawable-ldpi        //240x320
drawable-mdpi        //320x480
drawable-hdpi        //480x800
drawable-xhdpi       //720x1280
drawable-xxhdpi      //1080X1920
drawable-xxxhdpi     //1440X2560

И добавьте это в свой манифест

 <supports-screens
        android:anyDensity="true"
        android:largeScreens="true"
        android:normalScreens="true"
        android:resizeable="true"
        android:smallScreens="true"
        android:xlargeScreens="true" />

Исправьте свой xhdpi

person IntelliJ Amiya    schedule 06.05.2020
comment
Я изменил размер изображения xhdpi, он все еще сужен внутри. изображение, снимок экрана - person Cattaleya; 07.05.2020