2025年安卓横竖屏切换后,应用只展示半屏问题 AndroidAutoSize

安卓横竖屏切换后,应用只展示半屏问题 AndroidAutoSize项目使用的是这个屏幕适配框架 GitHub JessYanCodin AndroidAutoS A low cost Android screen adaptation solution 今日头条屏幕适配方案终极版 一个极低成本的 Android 屏幕适配方案 最近需要做一个特殊设备的横竖屏切换适配

大家好,我是讯享网,很高兴认识大家。

项目使用的是这个屏幕适配框架:GitHub - JessYanCoding/AndroidAutoSize: 🔥 A low-cost Android screen adaptation solution (今日头条屏幕适配方案终极版,一个极低成本的 Android 屏幕适配方案).

最近需要做一个特殊设备的横竖屏切换适配,发现了几个问题:

  1. 从横屏切换为竖屏时,只显示上半屏,下半屏是黑的
  2. 横竖屏切换时,没有重建Activity(AndroidManifest.xml中没有配置应用自行处理横竖屏切换,是让系统重建,但是系统并没有重建)
  3. 横竖屏切换时,onConfigurationChanged中给出的新的配置里面的屏幕方向仍然是横屏(也就是说系统不认为屏幕方向变化,没有重建Activity)

一度认为是固件问题,或者AndroidAutoSize框架问题,因为没有使用AndroidAutoSize的项目,就是好的,不会出现切换后半屏的问题。

最后发现问题原因是resizeableActivity这个属性。

官方文档:

Indicates that it is okay for this activity to be put in multi-window mode. Intended for a multi-window device where there can be multiple activities of various sizes on the screen at the same time.
The default value is false for applications with targetSdkVersion lesser than {@link android.os.Build.VERSION_CODES#N} and true otherwise.
Setting this flag to false lets the system know that the app may not be tested or optimized for multi-window environment. The system may still put such activity in multi-window with compatibility mode applied. It also does not guarantee that there will be no other apps in multi-window visible on screen (e.g. picture-in-picture) or on other displays. Therefore, this flag cannot be used to assure an exclusive resource access.
NOTE: A task's root activity value is applied to all additional activities launched in the task. That is if the root activity of a task is resizeable then the system will treat all other activities in the task as resizeable and will not if the root activity isn't resizeable.
NOTE: The value of {@link android.R.attr#screenOrientation} is ignored for resizeable activities when in multi-window mode.

翻译:


讯享网

表示可以将此活动置于多窗口模式。适用于多窗口设备,在该设备中,屏幕上可以同时显示多种不同大小的活动。
对于targetSdkVersion小于{@link android.os.Build.VERSION_CODES#N}的应用程序,默认值为false,否则为true。
将此标志设置为false可以让系统知道应用程序可能未针对多窗口环境进行测试或优化。系统仍然可以在应用了兼容模式的多窗口中放置这样的活动。它也不能保证在屏幕上(如画中画)或其他显示器上不会看到多窗口中的其他应用程序。因此,此标志不能用于确保独占资源访问。
注意:任务的根活动值应用于任务中启动的所有其他活动。也就是说,如果任务的根活动是可调整的,那么系统会将任务中的所有其他活动视为可调整的;如果根活动不可调整,则系统不会。
注意:在多窗口模式下,可调整大小的活动将忽略{@link android.R.attr#screenOrientation}的值。

就是说跟应用的targetSdkVersion有关,targetSdkVersion小于24的,默认为false,表示该应用没有针对多窗口环境进行适配和优化。

24以上的默认为true。

可能是由于这个机型特殊,横屏切换为竖屏时,采用了多窗口模式,导致下半屏未显示内容。

android:resizeableActivity="true"

讯享网

加上这个配置后,系统认为我们已针对多窗口做出优化,从而不会自行进入多窗口模式。

小讯
上一篇 2025-03-07 10:14
下一篇 2025-03-31 08:10

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/61904.html