0
votes

I used an image as background of splash screen, it's been resized for different pixel densities:

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>

It works fine on emulator, however on Samsung Galaxy M20, A7, S9 etc (resolution 2340x1080, screen density xhdpi) it looks narrowed inside. Any solution for that?

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>

1
@IntelliJAmiya no, still narrowed inside, screenshot in my last comment under your answerCattaleya
Show us your xml pleaseIntelliJ Amiya
i copied splash_screen.xml and posted above along with styles.xmlCattaleya
Where you calling splash_screen xml. Please provide main xmlIntelliJ Amiya
@IntelliJAmiya in AndroidManifest.xml, posted above.Cattaleya

1 Answers

1
votes

Read official guideline about Support different pixel densities.

To provide good graphical qualities on devices with different pixel densities, you should provide multiple versions of each bitmap in your app—one for each density bucket, at a corresponding resolution.

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

And add this in your manifest

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

Rectify your xhdpi