飞溅屏幕内部变窄



我使用了一张图像作为启动屏幕的背景,它已经根据不同的像素密度调整了大小:

hdpi-480x800mdpi-320x480xhdpi-768x1280xxhdpi-1080x1920xxxhdpi-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>

它在模拟器上运行良好,但在三星Galaxy M20、A7、S9等(分辨率2340x1080,屏幕密度xhdpi(上,它看起来内部变窄了。有什么解决方案吗?

Nexus 4(xhdpi(

三星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>

阅读关于Support different pixel densities的官方指南。

在具有不同像素的设备上提供良好的图形质量密度,您应该在app——每个密度桶一个,分辨率相应。

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" />

纠正您的xhdi

最新更新